C Data Structure-linear table (sequence table)

Source: Internet
Author: User
# Include <stdio. h> # Include <Stdlib. h> # Define Maxlength 1000 Typedef  Struct  {  Int  Total;  Int  Date [maxlength];} linelist;  Void Showlist (linelist * List ){  Int  I;  If (List-> total =0  ) {Printf (  "  Empty linear table \ n  "  );  Return  ;} Printf (  "  Current linear Table Status:  "  );  For (I = 0 ; I <list-> total; I ++ ) {Printf (  " % D \ t  " , List-> Date [I]);} printf (  "  \ N  "  );}  Void Output (linelist * List) {system (  "  CLS  "  ); Printf (  "  -- Sequence table -- \ n  " ); Printf (  "  A.-Add node I and-insert node \ n  "  ); Printf (  "  D.-delete node E and-exit \ n  "  ); Showlist (list);} linelist * Createlist () {linelist * List = (linelist *) malloc ( Sizeof  (Linelist); List -> Total = 0  ; Return  List ;}  Void Appendnode (linelist * List, Int  Val ){  If (List-> total < Maxlength) {list -> Date [list-> total] = Val; List -> Total ++ ;}}  Void Insertnode (linelist * List, Int Val, Int  Pos ){ Int  I;  If (Pos < 0 | POS> list-> Total) {printf (  "  The insertion location is incorrect.  "  );}  For (I = Pos; I <list-> total; I ++ ) {List -> Date [I + 1 ] = List-> Date [I];} List -> Date [POS] =Val; List -> Total + = 1  ;}  Void Deletenode (linelist * List, Int  Pos ){  If (Pos < 0 | POS> list-> Total) {printf (  "  The deleted node does not exist.  "  );}  Else {  Int  I;  For (I = Pos; I <list-> total; I ++ ) List -> Date [I] = List-> date [I + 1  ]; List -> Total -- ;}}  Void  Main (){  Int  Key, Pos;  Char  Act; linelist * Mylist =Createlist ();  While ( 1  ) {Output (mylist); printf (  "  Please perform the following operations:  "  ); Act = Getchar (); fflush (stdin );  Switch  (ACT ){  Case   '  A  ' : Printf (  "  Enter the key to add  "  ); Scanf (  "  % D  " ,& Key); appendnode (mylist, key );  Break  ;  Case   '  I  ' : Printf (  "  Enter the key and POs to be inserted.  "  ); Scanf (  "  % D  " , & Key ,& Pos); insertnode (mylist, key, POS );  Break  ;  Case   '  D  ' : Printf (  "  Enter the POs to delete  "  ); Scanf (  "  % D  " ,& Pos); deletenode (mylist, POS );  Break  ;  Case   '  E  ' : Exit (  0  ); Output (mylist); fflush (stdin );  Break  ;  Default  :  Break  ;}}} 

An ordered table stores all elements in a linear table to a specified Continuous Bucket according to its logic ···

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.