Home > Back-end >  C sequence table data structure
C sequence table data structure

Time:10-30

#include
using namespace std;
# define LISE_INIT_SIZE 10
# define TRUE 1
# define FALSE 0

Typedef struct {
Int elem [LISE_INIT_SIZE];
int length;
Int listsize;
} SqList;
//table attribute
SqList * CreateSqList () {
SqList * list;
The list - & gt; Listsize=LISE_INIT_SIZE;
The list - & gt; Length=0;
return list;
}//build table

Void Insert (SqList * list, int, int data) {
If (i<1 | | i> The list - & gt; Length + 1) {
cout<" The error "& lt; } else {
If (the list - & gt; Length>=list - & gt; Listsize) {
The list - & gt; Listsize=list - & gt; Listsize + 10;
} else {
for(int j=i; j<=list - & gt; Length; J++) {
The list - & gt; Elem [j + 1)=list - & gt; Elem [j];
} the list - & gt; Elem [I]=data;
The list - & gt; Length++;
cout<" Insert success "& lt; }
}
for(int i=0; i<=list - & gt; Length; I++) {
cout}

}//insert element

Void the Delete (SqList * list, int I) {
If (i<1 | | i> The list - & gt; Length + 1) {
cout<" Error "& lt; } else {
For (int j=list - & gt; Length; J> i; J -) {
The list - & gt; Elem [1]=list - & gt; Elem [j];
} the list - & gt; Length -;
for(int i=0; i<=list - & gt; Length; I++) {
cout}
}
}//delete

Void the Read (SqList * list, int I) {
If (i<1 | | i> The list - & gt; Length + 1) {
cout<" Error "& lt; } else {
cout}
}//read a
element in the table
Void getMax (SqList * list) {
Int e=list - & gt; Elem [0].
for(int i=1; iIf (eE=list - & gt; Elem [I];
}
cout}//query and largest element output

Void getMin (SqList * list) {
Int e=list - & gt; Elem [0].
for(int i=1; iIf (e> The list - & gt; Elem [I])
E=list - & gt; Elem [I];
}
cout}//query the smallest element and output

Void the Find (SqList * list, int data) {
for(int i=0; i<=list - & gt; Length; I++) {
If (the list - & gt; Elem [I]=={
the data)cout<" Have found!!!!! It in: "& lt; } else {
cout<" Without the data!!!!! "& lt; }
}
}//look for the element

Int the Queue (SqList * list) {
For (int I=list - & gt; Length, change=TRUE; I>=1 & amp; & Change; - I) {
Change=FALSE;
for(int j=0; jIf (the list - & gt; Elem [j] & gt; The list - & gt; Elem [m + 1]) {
Int p=list - & gt; Elem [j];
The list - & gt; Elem [j]=list - & gt; Elem [j + 1);
The list - & gt; Elem [j + 1)=p;
Change=TRUE;
}
}
}
for(int i=0; i<=list - & gt; Length; I++) {
cout}
return 1;
}//sorting

Void Invert (SqList * list) {
For (int I=0, j=list - & gt; Length - 1. i<=j; I++, j -) {
Int p=list - & gt; Elem [I];
The list - & gt; Elem [I]=list - & gt; Elem [j];
The list - & gt; Elem [j]=p;
}
for(int i=0; i<=list - & gt; Length; I++) {
cout}
}//inverse buy

Void Input (SqList * list, int n) {
cout<" Please enter each: ";
for(int i=0; iCin> The list - & gt; Elem [I];
The list - & gt; Length++;
}
}//input

Void the Output (SqList * list) {
for(int i=0; i<=list - & gt; Length; I++) {
cout}
}//output

Void UnionList (SqList * La, SqList * Lb, SqList * Lc) {
int i=0,j=0,k=0;
For (I, k; i<=La - & gt; Length, k<=La - & gt; Length + Lb - & gt; Length; I++ k++) {
Lc - & gt; Elem [k]=La - & gt; Elem [I];
}
For (j, k; j<=Lb - & gt; Length, k<=La - & gt; Length + Lb - & gt; Length; J++ k++) {
Lc - & gt; Elem [k]=Lb - & gt; Elem [j];
}
for(int i=0; i<=Lc - & gt; Length; I++) {
cout}
}//merge order table and output

Int main () {
SqList * L;
L=CreateSqList ();
Input (L, 5);
The Output (L);
Insert (L, 3, 10);
Delete (L, 4);
Read (L, 2);
GetMax (L);
GetMin (L);
Find (L, 10);
The Queue (L);
Invert (L);
The Output (L);
return 1;
}



Why would such an error here=-=



  • Related