c program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sekitoleko
    New Member
    • Sep 2006
    • 21

    c program

    draw the final queue after following operations have been performed on an empty queue.
    push(4),pop(),p ush(7),push(8), pop(),push(7),p ush(9),pop(),pu sh(8),push(5)
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    It would help if you showed some of your progress, so rather than give you the answer, I'll trry to explain how a queue works...

    A queue (much like a physical queue) is a First In, First Out structure. You can picture it as a tube running left to right. When something is pushed tyo a queue, it enters from the left hand side, and moves as far right as it can (without overtaking another element). When you pop something from the queue, you take the next element from the right hand side.

    What this question is asking is what is the order (right to left) of the elements left in the queue after these operations.

    Simple Example:
    Code:
    push(a) 
     Queue = {a}
    
    push b
     Queue = {b, a}
    
    push c
     Queue = {c, b, a}
    
    pop
      Queue = {c, b}       -      [and a is returned]
    I leave it to design the queue with your values.....

    Comment

    Working...