PLinkType de_Type(PLinkType pltype, DataType j) {int i; i=0; if(pltype->base!=pltype->top){ printf("The pop type list is:/n"); while(pltype->base!=pltype->top &&i<j){ printf("%d/t",pltype->base->link->info); pltype->base=pltype->base->link; i++;} printf("/n%d number(s) has been detyped",i);} if(pltype->base==pltype->top){ printf("/nAll the type have been detyped");} return(pltype); }
PLinkType pop_Stack(PLinkType pltype,DataType j) {PNode temp; int i; i=0; if(pltype->top!=pltype->base){ printf("The pop stack is:/n"); while(pltype->top!=pltype->base &&i<j){ temp=pltype->base; if(temp->link!=pltype->top){ while(temp->link != pltype->top) temp=temp->link; pltype->top->link=pltype->top; pltype->top=temp; printf("%d/t",pltype->top->link->info); i++;} else{pltype->top->link=pltype->top; pltype->top=temp; printf("%d/t",pltype->top->link->info); i++;}} printf("/n%d number(s) have been poped/n",i); return(pltype);} return(pltype); }
PLinkType free_all(PLinkType pltype) {PNode temp; while(pltype->base!=pltype->top){ temp=pltype->top; pltype->base=pltype->base->link; free(temp);} free(pltype->base); free(pltype); printf("All the Nodes and pointer have been freed/n"); }
void main() { PLinkType pltype; PNode pastack; int j1,j2,j3,j4,j5,k; int m1,m2,m3,m4,m5,n1,n2,n3,n4,n5; pltype=CreatePointer(); CreateHeadNode(pltype); printf("please choose the type of data struct:/n"); printf("1:linklist, 2:linkstack,3:linkqueue,0:to exit/n"); scanf("%d",&k); while(k!=0){ switch(k){ case 1:{printf("Input the length of linklist:/n"); scanf("%d",&m1); while(m1<1 ){ printf("The length is illegal,please input again/n"); scanf("%d",&m1);} push_Type(pltype,m1); printf("The link list is"); print_Type(pltype); printf("/nIf you want to enlist or delist,please choose/n"); printf("1: to enlist, 2: to delist, 0:to struct choose/n"); scanf("%d",&m2); while(m2!=0){ switch(m2){ case 1:{printf("Input the length of the list/n"); scanf("%d",&m3); while(m3<1 ){ printf("The length is illegal,please input again/n"); scanf("%d",&m3);} push_Type(pltype,m3); printf("The link list is:"); print_Type(pltype);} break; case 2:{if(pltype->base==pltype->top){ printf("The link list is empty/n");} else{ printf("please input number(s) that you want to delist:/n"); scanf("%d",&m4); de_Type(pltype,m4); printf("/nThe&n