stacks-turbo C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chubbykelly
    New Member
    • Aug 2006
    • 1

    #1

    stacks-turbo C

    hi, i got a prob with the new topic my teacher in data struct taught us
    this afternoon. he introduced the concept of stacks. simulated how 5
    elements will be pushed and popped out to the array elements and arrange
    them in ascending order. but he did not show the c program for it. i
    want to learn how to program it. can u help me with this please?


    thanks,
    kelly
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    Can you give an example?

    The idea would be to put the biggest numbers on the stack first. If they aren't the biggest, pop as many off as necessary, push the new biggest number on, then push the remaining ones back on until they are ready to be popped (the smallest).

    Comment

    • Ashok P
      New Member
      • Aug 2006
      • 3

      #3
      Hi,
      CODE : #define STACK_SIZE 5
      int top = -1; //global dec.
      if (top == STACK_SIZE)/*seperate fun called push*/
      {
      printf("stack is full"); LOGIC
      return
      }
      s[top++] = item;

      /* write seperate fun for pop() */
      if (top == -1)
      {
      printf("empty stack");
      return;
      }
      printf("deleted item is %d",s[--top]);


      try this one it should work.

      Comment

      Working...