Python 🐍

numList = [5, 3, 4, 1, 2]
numList.sort()

Python has a simple function to sort lists. Just call list.sort() to sort a list.

JavaScript 💻

var numList =  [5, 3, 4, 1, 2];
numList.sort();

JavaScript has the same function as python — just call list.sort() to sort a list.

Java 🖱️

import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
public class Main {
    public static void main(String[] args) {
        List<Integer> numList = new ArrayList<Integer>();
        numList.add(5);
        numList.add(3);
        numList.add(4);
        numList.add(1);
        numList.add(2);
        Collections.sort(numList);
    }
}

Java's method is a bit more complicated. You must use the Collections library to sort a list.

C++ 🐱‍💻

#include <list>
using namespace std;
int main(void) {
   list<int> numList = {5, 3, 4, 1, 2};
   numList.sort();
}

This code starts off by including the list library. The library allows us to create a list and call list.sort().

Share this project:

Updates