在线性表中给n个元素赋值
IDE是VS2013
#include "stdafx.h"
#include<list>
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
list<int> l;
int i=0,temp,amount;
cin >> amount;//输入线性表元素个数
/*for (i=0; i<5; i++)
{
cin >> temp;
l.push_back(temp);
}*/
while (i < amount)
{
cin >> temp;
l.push_back(temp);
i++;
}
l.sort();//线性表排序
for (auto p : l)//输出
{
cout << p << ' ';
}
cout << endl;
system("pause");
return 0;
}
本文介绍了如何使用C++的STL库中的list容器,在线性表中批量输入元素并进行排序的过程。通过VS2013 IDE实现,包括输入元素个数、逐个读取输入并插入列表、使用sort函数排序,以及最终输出排序后的列表。
6425

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



