#include
# define LIST_INIT_SIZE 100
# define LIST_INCREMENT 10
using namespace std;
Struct Sqlist {
Newlist elem long * and *;
Int Length;
Int listsize;
};
Void Error (char * s)
{
Cout & lt;
The exit (1);
}
Void InitList_Sq (Sqlist & amp; L)//create table contains a number of data elements order
{
L.e lem=new long [LIST_INIT_SIZE];
if (! L.e lem)
The Error (" Overflow!" );
L.L ength=0;
L.l istsize=LIST_INIT_SIZE;
}
Void Create_Sq (Sqlist * L)
{
Int I, num;
Cout & lt; <"Please enter the number sequence table element:";
Cin & gt;> num;
Cout & lt; <"Please input data elements:";
For (I=0; i
{
Cin & gt;> L-> Elem [I];
L-> Length++;
}
Cout & lt; <"Create order table: success!"
}
Void Increment (Sqlist & amp; L)//to order table extended LIST_INCREMEN space of data element
{
L.n ewlist=new long [L.l istsize + LIST_INCREMENT];//LIST_INCREMENT additional storage space
if (! L.n ewlist)
The Error (" Overflow!" );//storage allocation failure
For (int I=0; i
{
L.n ewlist [I]=L.e lem [I];
}//release of the original element occupies space
L.e lem=L.n ewlist;//handed over to the first address space;//transfer space first address
The delete [] L.e lem.
L.l istsize +=LIST_INCREMENT;//modify the current order form the largest space
}
Void ListInsert_Sq (Sqlist & amp; L, int, int) e
//in the first before I place order in table L insert element e; If the insert position is not reasonable, exit, related information is given and the
//I reasonable range is 1 & lt;=i<=L.l ength + 1
{
If ((i<1) | | (i> L.L ength + 1))//insert element parameters unreasonable
The Error (" Position Error!" );
If (L.L ength & gt;=LIST_INIT_SIZE)//if the current storage space is full, then increase the space
Increment (L);//add space function
Long * q=& amp; (L.e lem] [I - 1);//pointer q to insert
Long * p=& amp; (L.e lem [L.L] ength - 1);
For (p; P & gt;=q; P -)//to move backward elements
{
* (p + 1)=* p;
}
* q=e;//in the first position insert element in the I e L
L.L ength++;//modify the current length of the sequence table
}
Void ListDelete_Sq (Sqlist & amp; L, int, int & amp; E)
//delete order form in the ith element and returns its value e
{
If (i<1 | | i> L.L ength)//delete elements of unreasonable parameter
The Error (" Position Error!" );
E=L.e lem [I - 1);//to assign values of the elements is to be deleted to e
Long * p=& amp; (L.e lem] [I - 1);//point to delete the location of the place element
For (+ + p; p <=(L.e lem + L.L ength - 1); P++)//in order to move forward element
{
* (p=* p - 1);
}
L.L ength -;
Cout & lt; <"Remove elements is:";
Cout & lt;
}//modify the length of L
Int LocatElem_Sq (Sqlist L, int e)
{
Int j=1;
Long * q=L.e lem.
While ((j & lt;=L.L ength) & amp; & (* q!=e))
{
j++;
Q++;
}
If (j & lt; L.L ength)
Return j;
The else
return 0;
}
Void getElem_Sq (Sqlist L, int, int & amp; E)//output in order to operate in the table of the elements
{
If ((i<1) | | (i> L.L ength))//whether the output request parameters reasonable
The Error (" Position Error!" );
E=L.e lem [I - 1); With e//return a list of the order of the ith element values
Cout & lt;
}
Void printElem_Sq Sqlist (L)//output sequence in the table all the elements of existing
{
Cout & lt; <"The elements in the sequence table is as follows:" & lt;
int i;
For (I=0; i
{
Cout & lt; <" "& lt;
}
Cout & lt;
}
Int main ()
{
Sqlist L;
Int e, n, the number;
While (1)
{
Cout & lt; <"1, create information table" & lt;
Cout & lt; <"2, insert element" & lt;
Cout & lt; <"3, query element" & lt;
Cout & lt; <"4, remove elements" & lt;
Cout & lt; <"5, exit the program" & lt;
Cout & lt; <"Please choose to perform the operation:";
Cin & gt;> n;
The switch (n)
{
Case 1:
InitList_Sq (L);
Create_Sq (& amp; L);
PrintElem_Sq (L);
break;
Case 2:
Cout & lt; <"Please input the position of the insert and elements:";
Cin & gt;> Number & gt;> e;
While (e!=0)
{
ListInsert_Sq (L, number, e);
PrintElem_Sq (L);
Cout & lt; <"Please input the position of the insert and elements:";
Cin & gt;> Number & gt;> e;
}
break;
Case 3:
Cout & lt; <"Please enter a search elements:";
Cin & gt;> e;
While (e!=0)
{
LocatElem_Sq (L, e);
Cout & lt; <"The element is located the position of the sequence table is:" & lt;
Cout & lt; <"The element is:";
GetElem_Sq (L, LocatElem_Sq (L, e), e);
Cout & lt; <"Please enter a search elements:";
Cin & gt;> e;
}
break;
Case 4:
Cout & lt;