# include & lt; Iostream>
# define Maxsize 10
using namespace std;
Typedef struct {
The int data [Maxsize];
int length;
} SqlList;
//table long, returns to the length of the linear table L, or the number of data elements in L
{int Length (SqlList L)
Return L.l ength;
}
//in order to find the first element in table L value is equal to the e element, and returns its order
Int LocateElem (SqlList L, int e) {
for (int i=0; i
Return the I + 1;
}
return -1;
}
//by a find operation, get the position of the element I in table L the value of the
Int GetElem (SqlList L, int I) {
If (I & gt; Length (L) | | I & lt; 1)
Throw "this index is not true".
Return L.d ata [I - 1);
}
///initialization list, construct a linear table of empty
Void InitList (SqlList & amp; L) {
L.length=0;
}
//insert operation, on the position of the ith a in table L insert specified element e
Bool InsertList (SqlList & amp; L, int index, int e) {
If (index & gt; L.l ength | | index & lt;=0)
return false;
For (int I=L.l ength; I & gt;=index; I -) {
L.d ata [I]=L.d ata [I - 1);
}
L.d ata [index - 1]=e;
L.l ength++;
return true;
}
//delete, delete the position of the element in the ith in table L
Bool DeleteList (SqlList & amp; L, int index, int & amp; E) {
If (index & gt; L.l ength | | index & lt;=0)
return false;
E=L.d ata [index - 1);
For (int I=index; i
}
L.l ength -;
return true;
}
///create the starting list data
Bool CreateList (SqlList & amp; L, int n) {
If (n & gt; Maxsize | | n & lt;=0)
return false;
cout <"Please enter" & lt;
L.l ength++;
}
}
Void PrintList (SqlList & amp; L) {
for (int i=0; i
cout
//to empty, and if L is empty table, return true, otherwise it returns false
Bool Empty (SqlList L) {
If (Length (L))
return true;
The else
return false;
}
Int main () {
SqlList L;
InitList (L);
Printf (" please enter to create a table length: ");
int n;
Cin & gt;> n;
CreateList (L, n);
PrintList (L);
cout
cout <"Element is a place in the table 4:" & lt; Int data=https://bbs.csdn.net/topics/GetElem (L, 3);
cout <"A sequence of three element values as" & lt;
cout <"After the insert list:" & lt;
Int e=1;
DeleteList (L, 3, e);
cout <"Remove elements as:" & lt;
system("pause");
return 0;
}
CodePudding user response:
What's the problem?