488 Programming and Data Structures
vo id show ()
{
in t j ;
p r i n t f ( 8tack elements are : " ) ;
fo r (jaO;j<10;j++)
stack[j]1*0 ?
p r in t f (" %d , stack[j]) : p r in t f
>
OUTPUT:
push operation:
stack elements are: 5
stack elements are: 5
stack elements are: 5 8 9
pop operation:
stack elements are: 5
8 9
stack elements are: 5
stack elements are: 5
Explanation In the above program stack [] and top variables are declared as static. The variable
top is initialized with -1. It is not necessary to declare top as static. The push () operation inserts an
element into the stack. The next element pushed () is displayed after the first element and so on.
The pop () operation removes the element from the stack. The last element inserted is deleted first.
In the output the element 9 is deleted first as it is entered last.
14.15 QUEUES
This section describes the queue and its types. This data structure is very useful in solving various
real life problems. One can simulate the real life situations with this data structure. The theory of a
queue is common to all. We come across it in every occupation. Queue of people in a bank and
queue for tickets at railway station are examples of queue. As such, many examples can be described.
A queue is a non-primitive, linear data structure, and a subclass of list data structure. It is an ordered,
homogenous collection of elements in which elements are appended at one end called rear end and
elements are deleted at other end called front end. The meaning of front is front (face side) and rear
means back side. The information is manipulated in the same sequence as it was collected. Queue
follows the rule first in first out (FIFO). Fig. 14.12 illustrates a queue.
Fig. 14.12 Queues
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.126.199