#include <stdio.h> #include <stdlib.h> #define MAXSIZE 100struct list{int element[maxsize]; Maximum number of nodes in a linked list int len; The current list length}*t;void print (list *t), int isemtty (list *t)//Determine if the list is empty {if (t->len==0) return 0;elsereturn-1;} void GetElement (List *t,int i)//Gets the first element of the table (subscript starting from 0) {if (i<0| | I>t->len) printf ("fail!\n"); elseprintf ("%d\n", T->element[i]);} void Add (List *t)//Add node {int i,j;printf ("Input the Count of new Numner:") to the linked list, scanf ("%d", &j);p rintf ("Input new numbers:\n"); for (i=0;i<j;i++) {scanf ("%d",& (T->element[i])); t->len++;} printf ("Add success!\n");} Insert (List *t) {int i,j,x;printf ("Input the value of I and x:"); Insert a node scanf ("%d%d", &i,&x) before the first node in the table, if (i<=0| | i>t->len| | T->len==maxsize)//Can be inserted in the condition printf ("Can not insret!\n"), else{for (j=t->len;j>=i;j--) {t->element[j]=t- >element[j-1]; Move all nodes back from the insertion position} t->element[i]=x; t->len++; }}void Delete (list *t,int i)//delete table section Idot {int j;if (i<0| | I>=t->len) printf ("Can not delete!\n"), else{for (j=i;j<t->len;j++) t->element[j]=t->element[j+1]; Move all nodes forward t->len--from the next node in the deleted position;}} void Clear (List *t)//Empty list {t->len=0;} void Modify (List *t,int i)//Modify the list i node {int b;printf ("Intut a Number:"), scanf ("%d", &b); if (i<0| | I>t->len) printf ("Can not modify!\n"); elset->element[i]=b;} void Show (List *t)//display data for all nodes in the list {int i=0;for (; i<t->len;i++) printf ("%2d", T->element[i]);p rintf ("\ n");} int main () {struct List *p; P=new List;p->len=0;int ch,i,x; m:printf ("******************************************************\n");p rintf ("1.judge 2.Getelement 3.add 4.delete \ n 5.insert 6.show 7.modify 8.clear 0.quit\n ");p rintf (" ******************************************************\n "); printf ("Please input your choice:"); scanf ("%d", &ch); switch (CH) {case 1:printf ("%d\n", Isemtty (p)); Goto m; Case 2: {printf ("Input a number:"); scanf ("%D ", &i); GetElement (p,i); goto m;} Case 3:add (p); goto m; Case 4: {printf ("Input value of I:"); scanf ("%d", &i);D elete (p,i); Goto m; }case 5:insert (p); goto m;case 6:show (p); goto m; Case 7: {printf ("Input value of I:"); scanf ("%d", &i); modify (p,i); goto m; }case 8:clear (P); Goto m; Case 0:exit (0); Default:break;} return 0;}
Create a sequential table and implement various actions (C language)