Sequence List

xiaoxiao2021-03-05  24

#include #include #include #include

# Define list_init_size 100 # define listincrement 10typedEf char DataType;

Typedef struct {datatype * elem; int LENGTH; INT LISTSIZE;} SEQLIST

// Initialize sequence listint initseqlist (seqlist * list) {list-> elem = (datatype *) malloc (list_init_size 1) * sizeof (datatype));

IF (NULL == List-> ELEM) {Printf ("ERROR IN MEMORY !!!! / N); Return 0;}

List-> length = 0; list-> listsize = list_init_size; printf ("INITIALIZATION SUCCESSED !! / N"); Return 1;}

// Insert data into the sequence listint InsertSeqList (SeqList & list, int intPosition, DataType datatype) {if (list.length> = list.listsize) {DataType * newbase = (DataType *) realloc (list.elem, (list.listsize ListINcrement) * SizeOf (DATATYPE)); if (! Newbase) return 0; list.lex = newbase; list.listsize = listincrement; Printf ("create new base is enough./n");}} (intPosition < 1 || INTPSITION> List.length 1) {Printf ("Error !! The inserted data's position is outside the law! / Nplease try !! / n"); return 0;} else {for (int Num = list) .length; Num> = intPosition; Num--) {list.elem [Num 1] = list.elem [Num];} list.elem [intPosition] = DATATYPE; list.length ; printf ("Insert Successed./ N "); Return 1;}}}

// delete data in sequence listint deleteseqlist (seqlist * list, int idosition) {if (INTPSITION <1 || intPosition> list-> length || null == list-> listsize) {printf ("Error! NO Data IN this PLEASE TRY AGAIN! / N "); Return 0;} char Array [1024], * Choice; Printf (" Do you want to delete this data? (y OR N): "); scanf ("% s " CHOICE = array; switch (* choice) {case 'y': case 'y': for (int Num = INTPSITION 1; Num <= list-> length; num ) {list-> ELEM [NUM] = list-> ELEM [NUM 1];} list-> length -; printf ("delete successed! / n"); Return 1; Break;

Case 'N': Case 'N': Return 0; Break;

Default: Printf ("Warning !! you enter data of error! please try!"); Break;}}

// count sequence list sizesint lengthsEqlist (seqlist * list) {return list-> length;}

// search the data in the sequence listint searchseqlist (seqlist * list, datatype datatype) {return 0;}

// Return The Data in The Sequence ListDataType GetFromSEQLIST (SEQLIST * LIST, INT INTPSITION) {Return List-> ELM [INTPSITION];

// Display All of the data in the sequence listvoid showseqlist ("Display All of the data in the sequence list / n"); if (0 == List-> length) {Printf ("Sequence" List is null ");} else {for (int loop = 1; loop <= list-> length; loop ) {Printf ("% c ", list-> elem [loop]);} printf (" / n " }}

// main functionvoid main () {char Array [1024], * choice; int rtPosition, flag = 1, result; seqlist list; datatype dattype; while (flag) {printf ("/ n / n / n / t / t / t - sequence list - / n / n "); Printf (" / t ***************************** ****************** / N "); Printf (" / t * 1 - initialize sequence list * / n "); Printf (" / t * 2 - Insert Data) INTO SEQUENCE LIST * / N "); Printf (" / t * 3 - delete data in the sequence list * / n "); Printf (" / t * 4 - return sequence list's length * / n "); Printf (" / t * 5 - search data order by value * / n "); Printf (" / t * 6 - read element value * / n "); Printf (" / t * 7 - display sequence list * / n "); Printf ("/ t * 0 - exit * / n"); Printf ("/ t * / n"); Printf ("/ t * this demo is name by: radeon ling * / n"); Printf (" / t * email: radeon_ling@eastday.com * / n "); Printf (" / t * * / n "); Printf (" / t * copy right: 2005 millennium studio * / n "); printf (" / t ****************** **************************** / N "); Printf (" Please Chioce: "); scanf ("% s ", & array); choice = array; switch (* choice) {CASE '1': INITSEQLIST (& List); Break;

Case '2': Printf ("/ NPLEASE ENTER NUMBER POSITION AND VALUE. / N (Enter style: intPosition):"); scanf ("% d,% c", & intPosition, & datape); insertseqlist (List, INTPOSITION, DATATYPE; BREAK;

Case '3': Printf ("/ NPLEASE Enter Position of Deleted Value:"); Scanf ("% D", & INTPSITION); deleteseqlist (& list, intPosition); showseqlist (& list); break; case '4': result = Lengthseqlist (& List); Printf ("List Length IS% D / N", Result; Break;

Case '5': Result = Searchseqlist (& List, Datatype); Printf ("Need Software Update ............... / n"); Break;

Case '6': Printf ("Please Enter Position In The List:"); Scanf ("% D", & INTPSITION); Printf ("Position% D I% C. / N", INTPOSITION, GetFromSeqlist (& List, INTPSITION) Break;

Case '7': showseqlist (& list); Break;

Case '0': Printf ("Do You Want EXIT? (Y OR N)"); Scanf ("% s", & array); choice = array; if ('y' == * choice || 'y' = = * choice) {FLAG = 0; Printf ("End of Program ./nwelcome./N");} Break;

DEFAULT: Printf ("Error, please Enter 0 - 7, Try Angain! / N"); Break;}} Return;

转载请注明原文地址:https://www.9cbs.com/read-37319.html

New Post(0)