#include <stdio.h> #include <stdlib.h> #define N sizeof (Stacknode)//node as the number of bytes N//definition structure typedef int datatype;
typedef struct STACKNODE {datatype data;
struct Stacknode *next;
}stacknode;
Define stack top typedef struct {Stacknode *top;
int count;//count with}linkstack;
Into the stack, elements into the stack void Insertstack (Linkstack *s) {int x=0;
Stacknode *p;
s->top=null;
s->count=0;
printf ("\n\t Build a stack subsystem");
p= (stacknode*) malloc (N);
printf ("\n\t\t Please enter numbers one by one, end tag bit, do terminator number: 0 \ n");
while (1) {/*printf ("\t\t Please enter:");
Fflush (stdin); if (!scanf ("%d", &x)) {printf ("The type of element entered is wrong ...")
\ n ");
Continue
else if (x== ' # ') break;
else {p->data=x;
p->next=s->top;
s->top=p;
s->count++;
*/printf ("\t\t Please enter:");
p= (stacknode*) malloc (N);
Fflush (stdin); if (!scanf ("%d", &x)) {printf ("\t\t\t entered" element "kind of error ...)
\ n ");
Continue
else if (x==0) break;
else {p->data=x;
p->next=s->top;
s->top=p; s->count++;
printf ("\ n");
}//display stack element void Showstack (Linkstack *s) {Stacknode *p;
int i=0;
p=s->top;
i=s->count;
p->data=s->top->data; if (p->next==null) if (i==0) printf ("\t\t stack is an empty stack!!!!
\ n ");
else {printf ("every element in the \ t stack is: \ t");
while (i!=0) {printf ("%8d", p->data);
p=p->next;
s->top=s->top->next;
i--;
printf ("\ n");
//Find the number of elements in the stack void Lengthstack (Linkstack *s) {printf ("The number of elements in \ t stack is: \ t");
printf ("%d", s->count);
}//out stack, stack of each element of the stack void Putstack (Linkstack *s) {//int x;
Stacknode *p;
Linkstack *i;
if (s->count==0) {printf ("\t\t stack is an empty stack!!!!");
return 0;
else {/* p=s->top;
x=p->data;
s->top=p->next;
Free (p);
s->count-=1;
* * p=s->top;
s->top=s->top->next;
printf ("\n\t\t\t\t out stack element:%d\n", p->data);
Free (p);
s->count--;
}//System conversion, decimal conversion to binary void Shiftstack (Linkstack *s) {int z=0;
int m=0;
Stacknode *p;
printf ("Please enter the number to convert" z:\t); scanf("%d", &z);
s->top=null;
while (z) {m=z%2;
Z=Z/2;
p= (stacknode*) malloc (N);
p->next=s->top;
s->top=p;
s->top->data=m;
printf ("\n\t converted binary to \ t");
while (s->top) {p=s->top;
printf ("%d", p->data);
s->top=s->top->next;
Free (p);
printf ("\ n");
int main () {int A;
Linkstack s;
s.count=0;
Linkstack *s;
while (1) {printf ("\n\t\t\t\t\t\t stack subsystem \ n");
printf ("\t\t***************************************************\n");
printf ("\t\t* 1------into stack *\n");
printf ("\t\t* 2------out Stack *\n");
printf ("\t\t* 3------Display the element *\n in the stack");
printf ("\t\t* 4------to find the number of elements in the stack *\n");
printf ("\t\t* 5------conversion *\n"); printf ("\t\t* 0------return *\n ");
printf ("\t\t***************************************************\n");
printf ("Please enter (0-5) option: \ n");
printf ("\ n Please enter the number of functions you want to achieve: \ t");
Fflush (stdin);
scanf ("%d", &a);
if (a = = 1) insertstack (&s);
else if (a = = 2) putstack (&s);
else if (a = = 3) showstack (&s);
else if (a = = 4) lengthstack (&s);
else if (a = = 5) shiftstack (&s);
else if (a = = 0) return 0; else{printf ("!!!!! Input is incorrect, please re-enter!!!!!
\ n "); }
}
}