Closed Thread
Results 1 to 3 of 3

Thread: Stack of symbols

  1. #1
    zhenya is offline Newbie
    Join Date
    Dec 2009
    Posts
    13
    Rep Power
    0

    Post Stack of symbols

    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();        }}

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    theonejb's Avatar
    theonejb is offline Learning Programmer
    Join Date
    Jul 2009
    Location
    Lahore, Pakistan
    Posts
    52
    Rep Power
    0

    Re: Stack of symbols

    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...

  4. #3
    zhenya is offline Newbie
    Join Date
    Dec 2009
    Posts
    13
    Rep Power
    0

    Re: Stack of symbols

    (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("&#37;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];
    }

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Stack allocation and stack size
    By mircan in forum C and C++
    Replies: 3
    Last Post: 03-17-2010, 06:53 PM
  2. Occurrence of symbols
    By zhenya in forum C and C++
    Replies: 1
    Last Post: 03-08-2010, 09:48 AM
  3. Other way to declare Variables using Symbols
    By kresh7 in forum Visual Basic Tutorials
    Replies: 14
    Last Post: 09-25-2009, 08:00 AM
  4. Help matching all symbols except defined
    By Torrodon in forum PHP Development
    Replies: 3
    Last Post: 06-08-2009, 07:57 PM
  5. Question regarding symbols
    By soliver1982 in forum HTML Programming
    Replies: 2
    Last Post: 01-02-2007, 03:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts