main.cpp

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

CPP
72
字号
#include<iostream>
using namespace std;
#include "SortedList.h"

int main() {
	cout<<"输入表:"<<endl;
	SortedList<int,int> lst;
	lst.build();
	cout<<endl;
	lst.show();
	cout<<endl;
	cout<<"搜索元素:";
	int x;
	cin>>x;
	int r=lst.Search(x);
	if(r!=0)
		cout<<"元素位置:"<<r<<endl;
	else
		cout<<"无此元素"<<endl;

	cout<<endl;
	cout<<"搜索元素:";
	x;
	cin>>x;
	r=lst.BinarySearch(x,1,lst.Length());
	if(r!=0)
		cout<<"元素位置:"<<r<<endl;
	else
		cout<<"无此元素"<<endl;
	cout<<endl;
	cout<<"搜索元素:";
	cin>>x;
	r=lst.BinarySearch(x);
	if(r!=0)
		cout<<"元素位置:"<<r<<endl;
	else
		cout<<"无此元素"<<endl;
	cout<<"测试完毕"<<endl;

	while(1)//为了在类库说明文档中便于观察,加入这一句
		cout<<"";
	return 0;
}

/*
输入示例:
输入表:
请输入元素个数:4

输入元素值:1

输入元素值:2

输入元素值:3

输入元素值:4


表为:
1  2  3  4

搜索元素:1
元素位置:1

搜索元素:2
元素位置:2

搜索元素:3
元素位置:3
测试完毕

*/

⌨️ 快捷键说明

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