main.cpp

来自「清华大学计算机系数据结构课程教材《数据结构 用面向对象方法和C++描述》(殷人昆」· C++ 代码 · 共 77 行

CPP
77
字号
#include"SeqList.h"
#include<iostream>
using namespace std;
int main()
{
	SeqList<int> lst;
	lst.build();
	lst.show();

	cout<<"搜索元素:";
	int temp;
	cin>>temp;
	int pos=lst.Search(temp);
	if(pos==0)
		cout<<"没有这个元素!"<<endl;
	else
		cout<<"位置:"<<pos<<endl;

	cout<<"删除一个元素,输入删除位置:";
	cin>>pos;
	if(lst.Remove(pos,temp))
	{
		cout<<"被删元素:"<<temp<<endl;
		cout<<"删除后:"<<endl;
		lst.show();
	}
	else
		cout<<"删除失败!"<<endl;

	cout<<"插入一个元素,输入插入位置和元素值:";
	cin>>pos>>temp;
	if(lst.Insert(pos,temp))
	{
		cout<<"插入后:"<<endl;
		lst.show();
	}
	else 
		cout<<"插入失败!"<<endl;

	cout<<"测试完毕"<<endl;

    while(1)//为了在类库说明文档中便于观察,加入这一句
		cout<<"";
	return 0;
}
/*
输入示例:
开始建立顺序表,请输入表中元素个数:4
输入表元素:
1
输入表元素:
2
输入表元素:
3
输入表元素:
4
第1个元素: 1
第2个元素: 2
第3个元素: 3
第4个元素: 4
搜索元素:2
位置:2
删除一个元素,输入删除位置:3
被删元素:3
删除后:
第1个元素: 1
第2个元素: 2
第3个元素: 4
插入一个元素,输入插入位置和元素值:2 43
插入后:
第1个元素: 1
第2个元素: 2
第3个元素: 43
第4个元素: 4
测试完毕

*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?