One of the data structures: linear form of sequential storage structure

  • Linear form of sequential storage structure

/ 1. In order to achieve the linear form of sequential storage structure, two C libraries need to reference /
#include <stdio.h>
#include <stdlib.h>

/ 2. Application to a memory address space, the space 100 of the macro /
#define the MAXSIZE 100

/ Structure 3. define a linear sequence table /
typedef int the DataType;
typedef struct {
the DataType = Data *;
int length;
} SeqList;

/ 4. The method of statement allows the user to press any key /
void waitFor () {
the printf ( "\ n-press any key ... \ n-");
getchar ();
}

/ 5. The method of statement determines whether the user continues to make /
int go_on () {
char choce;
the while (. 1) {
IF (Choice == 'the Y' || Choice == 'Y')
BREAK;
IF (Choice == ' N '|| Choice ==' n-')
BREAK;
Exit (-1);
}
return (-1);
}

/ 6. The configuration of a linear sequence table empty /
void Init_SeqList (SeqList L) {
L -> Data = (the Datatype
) the malloc (the sizeof (the Datatype));
IF (! L -> Data) {
the printf ( "\ n-memory allocation failure . \ n-");
}
L -> length = 0;

/ 7. Linear Space sequence table input position and letting the user select element element /
void Insert_SeqList (SeqList L *, I int, the DataType X) {
int I, In Flag, insert_flag =. 1;
the while (. 1) {
the printf ( "Please enter the insertion position of the element: ");
Scanf ("% D ", & I);
the printf (" Please enter the element to be inserted ");
Scanf ("% D ", & X);

                            if(insert_flag = 1){
                                    printf("插入成功。\n");
                          else{
                                 printf("插入失败。\n");
                            flag = go_on();
            }

/ 8. Linear Space insertion sequence table element values /
int the Insert (SeqList L) {
the DataType
P, Q;
IF (L -> Data == the MAXSIZE) {
the printf ( "\ n-table is full, can not be inserted \ n-.");
return (-1);
IF (I <. 1 || I> L -> length +. 1) {
the printf ( "\ n-inserted position error, can not be inserted \ n-.");
return (0);
for (int = P (L -> Data [L -> length -. 1]); P> = Q; P -) {
(P +. 1) = P
}
Q = X;
L -> length ++;
return (. 1);

/ 9 to output and display /
int main () {
SeqList L;
char Choice;
int In Flag =. 1;
do {
the printf ( "\ n-");
the printf ( "----------- order table ( achieve dynamic array) ----------------------- \ n-");
the printf (.". 1 insert elements ---------------------- -------------------- \ the n-");
printf (" ---------------------- ------------------------------------ \ n-");
the printf (" Please select [] 1 / 2/3/4/0: ");
Choice = getchar ();
swicth (Choice) {
Case '. 1':
the Insert (& L);
BREAK;
}
waitFor ();
} the while (In Flag =. 1);
return 0;
}

Guess you like

Origin blog.51cto.com/dreamerhan/2452650
Recommended