Jump to content

Stack of symbols

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
zhenya

zhenya

    Newbie

  • Members
  • PipPip
  • 13 posts
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;
 
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();        }} 


#2
theonejb

theonejb

    Learning Programmer

  • Members
  • PipPipPip
  • 52 posts
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...

#3
zhenya

zhenya

    Newbie

  • Members
  • PipPip
  • 13 posts
(In case of concurrence of an entered symbol to top of a stack to deduce the size of a stack.)
As it to make??
 
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];
}