try_list.cpp
来自「这是数据结构初学者的极佳参考资料,里面有关意向链表的实现.」· C++ 代码 · 共 78 行
CPP
78 行
#include "stdafx.h"
#include "list.h"
void main()
{
int choose = -1, max_length, record, position;
cout << "max_length:";
cin >> max_length;
list<int> t_list(max_length);
while (choose != 0)
{
cout << endl << "-----------------------------" << endl
<< "1.empty" << endl
<< "2.full" << endl
<< "3.size" << endl
<< "4.clear" << endl
<< "5.insert" << endl
<< "6.remove" << endl
<< "7.retrieve" << endl
<< "8.replace" << endl
<< "9.show the list" << endl
<< "0.exit" << endl;
cin >> choose;
switch (choose)
{
case 1:
if (t_list.empty()) cout << "the list is empty" << endl;
else cout << "the list is not empty" << endl;
break;
case 2:
if (t_list.full()) cout << "the list is full" << endl;
else cout << "the list is not full" << endl;
break;
case 3:
cout << "the size of the list is " << t_list.size() << endl;
break;
case 4:
t_list.clear();
break;
case 5:
cout << "new record:";
cin >> record;
cout << "position:";
cin >> position;
t_list.insert(position, record);
break;
case 6:
cout << "position:";
cin >> position;
t_list.remove(position);
break;
case 7:
cout << "position:";
cin >> position;
t_list.retrieve(position, record);
cout << "[" << position << "]:\t" << record;
break;
case 8:
cout << "new record:";
cin >> record;
cout << "position:";
cin >> position;
t_list.replace(record, position);
break;
case 9:
for (position = 0; position < t_list.size(); position++)
{
t_list.retrieve(position, record);
cout << "[" << position << "]:\t" << record << endl;
}
break;
default: break;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?