题目:反序链表
程序:
#include<iostream>
#include<list>
#include<stack>
using namespace std;
int main()
{
cout<<"enter the list";
int tem;
stack<int> sta;
list<int> lis;
if(cin>>tem)
while(cin>>tem)
{
sta.push(tem);
cout<<"enter the list";
}
else cout<<"empty"<<endl;
int top;
while(!sta.empty())
{
top=sta.top();
lis.push_back(top);
cout<<top;
sta.pop();
}
return 0;
}
白痴级
反序链表实现
本文介绍了一个使用 C++ 实现的简单程序,该程序通过栈结构来帮助完成链表元素的反序输出。具体实现中利用了标准模板库 STL 中的 list 和 stack,程序首先读取一系列整数并将它们压入栈中,然后依次弹出并插入到链表的尾部,最终实现了链表元素的反向输出。
4499

被折叠的 条评论
为什么被折叠?



