It is necessary to create a stack for symbols. The size of a stack to enter from the screen.)
As it to make, here my attempt;
Code:struct steck {char c[10];struct steck *next;}*p1,*p2;static int a,n;void main(){ p2=NULL; p1=new(struct steck); printf("Razmer;"); scanf("%i",&n); if(n==NULL) printf("error"); else{ for(a=0;a<n;a++) { scanf("%s",&p1->c); p1->next=p2; p2=p1; } printf("Elements:\n");if(p1!=NULL){ printf(" %s",p1->c); p2=p1->next; //delete(p1); p1=p2;} getch(); }}
Clean up your code. I at least am just seeing all the code on one HUGE line. Its not fun trying to read something like that...
(In case of concurrence of an entered symbol to top of a stack to deduce the size of a stack.)
As it to make??
Code:typedef struct stack{ char data; struct stack *next; }Item,*p1; Item *top=NULL; void Push(void); void Pop(void); void Display(void); void razmer(void); static int a; int main(){ razmer(); int done=false; char c; while(!done){ Display(); printf("\n\nA)dd,D)elete,Q)uit \n"); c=getchar(); switch(toupper(c)){ case 'A': Push(); break; case 'D': Pop(); break; case 'Q': done=true; break; } } return 0; } void Push(){ Item *p; p=(Item *)malloc(sizeof(Item)); printf("Your symbol; "); scanf("%s",&p->data); p->next=top; top=p; } void Pop(){ Item *p; if(top!=NULL){ p=top; top=top->next; free(p); } } void Display(){ Item *p=top; if(p==NULL) printf("\nstack is empty \n"); else printf("\n\nStack;\n"); while(p!=NULL){ printf("\n%c",p->data); p=p->next; } } void razmer(){ int n; printf ("vvedi kolichestvo elementov\n"); scanf ("%d", &n ); char *data = new char[n]; }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks