DEV Community

Mujahida Joynab
Mujahida Joynab

Posted on

Sort List

`#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int val;
    list<int> lst;

    while (cin >> val && val != -1)
    {

        lst.push_back(val);
        lst.sort();
    }
    for (int num : lst)
    {
        cout << num << " ";
    }
    cout << endl;
}
`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)