DEV Community

Mujahida Joynab
Mujahida Joynab

Posted on

Reverse a List

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    list<int> list;
    int val;
    while (cin >> val && val != -1)
    {
        list.push_back(val);
    }
    list.reverse();
    for (int num : list)
    {
        cout << num << " ";
    }
}`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)