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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay