⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wq12.cpp

📁 各种算法的c语言程序
💻 CPP
字号:
#include "stdio.h"
#include "SqList.cpp"

void main(void)
{
	Sqlist L;
	int i,res,choice;
	ElemType e;
	InitList_Sq(L);//初始化顺序表
	cout<<"Creat the list now.\n";
	CreateList_Sq(L);//键盘输入长度及元素,建立顺序表
	cout<<"\nNow the list is:";
	ListDisplay_Sq(L);//屏幕输出顺序表内容
	
	//菜单
	for(;;)
	{
		cout<<"\nPlease choose:";
		cout<<"\n0.Display all the elements of the list;";
		cout<<"\n1.Insert an element into the list;";
		cout<<"\n2.Delete an element from the list;";
		cout<<"\n3.Destroy the list;";
		cout<<"\n4.Quit.";
		cout<<"\nchoose (0-4):";
		cin>>choice;
		switch(choice)
		{
		case 0:{cout<<"\nNow the list is:";ListDisplay_Sq(L);}break;
		case 1:
			{
				for(;;)
				{
					cout<<"\nInput the position you want to insert "<<endl;
					cout<<" (the length of the list is "<<ListLength_Sq(L)<<"),input 0 to quit :";
					cin>>i;
					if(i==0)break;
					cout<<"Input the element you want to insert:";
					cin>>e;
					res=ListInsert_Sq(L,i,e);
					if(res==ERROR)
						cout<<"\nPosition ERROR!";
					else if(res==OVERFLOW)
						cout<<"\nMemory OVERFLOW!";
					else 
						cout<<"\nElement Insert OK!";
					cout<<"\nNow the list is:";
					ListDisplay_Sq(L);
				}
				break;
			}
		case 2:
			for(;;)
			{
				cout<<"\nInput the position you want to delete\n(the length of the list is "<<ListLength_Sq(L)<<"), input 0 to quit:";
				cin>>i;
				if(i==0)break;
				res=ListDelete_Sq(L,i,e);
				if(res==ERROR)
					cout<<"Position ERROR!";
				else
				{
					cout<<"Element Delete OK! The element you delete is ";
					cout<<e;
				}
				cout<<"\nNow the list is:";
				ListDisplay_Sq(L);
			}
			break;
		case 3:
			{
				DestroyList_Sq(L);
				cout<<"List Destroy OK";
			}
			break;
		default:
			break;
		}//end of switch
	fflush(stdin);
	if(choice==0||choice==1||choice==2||choice==3)
		continue;
	else 
		break;
	
	}//end of for

}//end of main

⌨️ 快捷键说明

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