0% found this document useful (0 votes)
25 views3 pages

Ijirt101357 Paper

Uploaded by

Ashish Raturi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Ijirt101357 Paper

Uploaded by

Ashish Raturi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

© 2014 IJIRT | Volume 1 Issue 7 | ISSN: 2349-6002

RESEARCH PAPER ON STACK AND QUEUE


Nitesh, Manbir Singh, Rahul Yadav
Deparment Of Electronics And Communication
Dronacharya College Of Engineering
Farruknagar, Khetawas, Gurgaon

Abstract- This paper involves the concept of stack and


queue used in data structure basically two of the more
common data objects found in computer algorithms
are stacks and queues. Both of these objects are
special cases of the more general data object, an
ordered list.
A stack is a container of objects that are inserted and
removed according to the last-in first-out (LIFO)
principle. In the pushdown stacks only two operations
are allowed: push the item into the stack, and pop the
item out of the stack. A stack is a limited access data
structure - elements can be added and removed from The restrictions on a stack imply that if the
the stack only at the top. push adds an item to the top
elements A,B,C,D,E are added to the stack, n that
of the stack, pop removes the item from the top. If we
talk about the daily life example like a stack of
order, then thefirst element to be removed/deleted
books; you can remove only the top book, also you must be E. Equivalently we say that the last
can add a new book on the top. element to be inserted into the stack will be the first
to be removed. For this reason stacks are
I. INTRODUCTION sometimes referred to as Last In First Out (LIFO)
STACK Stop. Since the last item added to the list lists. The restrictions on queue imply that the first
element which is inserted into the queue will be the
is the first removed from the list, stacks are also
first one to be removed. Thus A is the first letter to
known as “Last A stack is an ordered list of items. be removed, and queues are known as First In First
Items are added to the list at the top and items are Out (FIFO) lists. Note that the data object queue as
removed from the In First Out” (LIFO) lists. A defined here need not necessarily correspond to the
stack is easily implemented in an array, requiring mathemathical concept of queue in which the
only a insert/delete rules may be different.
pointer variable to point to the position of the top II. STACK ITS APPLICATIONS AND
element of the stack. IMPLEMENTATION
Applications
• The simplest application of a stack is to
reverse a word. You push a given word to stack -
letter by letter - and then pop letters from the stack.
• Another application is an "undo"
mechanism in text editors; this operation is
accomplished by keeping all text changes in a
stack.
Backtracking. This is a process when you need to
queue
access the most recent data element in a series of
A queue is an ordered list in which all insertions
take place at one end, the rear, while all deletions elements. Think of a labyrinth or maze - how do
take place at the other end, the front. Given a stack you find a way from an entrance to an exit?
S=(a[1],a[2],.......a[n]) then we say that a1 is the Once you reach a dead end, you must backtrack.
bottommost element and element a[i]) is on top of But backtrack to where? to the previous choice
element a[i-1], 1<i<=n. When viewed as a queue point. Therefore, at each choice point you store on
with a[n] as the rear element one says that a[i+1] is a stack all possible choices. Then backtracking
behind a[i], 1<i<=n.queue operation are more simply means popping a next choice from the
helpful as campared to stack operation. stack.
Language processing:

IJIRT 101357 INTERNATIONAL JOURNAL OF INNOVATIVE RESEARCH IN TECHNOLOGY 584


© 2014 IJIRT | Volume 1 Issue 7 | ISSN: 2349-6002

space for parameters and local variables is created operations are allowed enqueue and dequeue.
internally using a stack. Enqueue means to insert an item into the back of
compiler's syntax check for matching braces is the queue, dequeue means removing the front item.
implemented by using stack.
The picture demonstrates the FIFO access.
support for recursion
The difference between stacks and queues is in
Implementation removing. In a stack we remove the item the most
In the standard library of classes, the data type recently added; in a queue, we remove the item the
stack is an adapter class, meaning that a stack is least recently added
built on top of other data structures. The underlying Implementation
structure for a stack could be an array, a vector, an In the standard library of classes, the data type
ArrayList, a linked list, or any other collection. queue is an adapter class, meaning that a queue is
Regardless of the type of the underlying data built on top of other data structures. The underlying
structure, a Stack must implement the same structure for a queue could be an array, a Vector, an
functionality. This is achieved by providing a ArrayList, a LinkedList, or any other collection.
unique interface: This isachieved by providing a unique interface.
public interface StackInterface<AnyType> interfaceQueueInterface‹AnyType>
{ {
public void push(AnyType e); publicbooleanisEmpty();
publicAnyType pop(); publicAnyTypegetFront();
publicAnyType peek(); publicAnyTypedequeue();
publicbooleanisEmpty();
public void enqueue(AnyType e);
}
The following picture demonstrates the idea of public void clear();
implementation by composition. }
Another implementation requirement (in addition Each of the above basic operations must run at
to the above interface) is that all stack operations constant time O(1). The following picture
must run in constant time O(1). Constant time demonstrates the idea of implementation by
means that there is some constant k such that an composition.
operation takes k nanoseconds of computational
time regardless of the stack size. IV. ALGORITHM ADDING AN ELEMET
IN A STACK
Array-based implementation
In an array-based implementation we maintain the procedure add(item : items); {add item to the
following fields: an array A of a default size (≥ 1), global stack stack; top is the current top of stack
and n is its maximum size} begin if top = n
the variable top that refers to the top element in the
thenstackfull; top := top+1; stack(top) := item;
stack and the capacity that refers to the array size. end: {of add}
The variable top changes from -1 to capacity - 1.
We say that a stack is empty when top = -1, and the V. DELETION IN STACK
stack is full when top = capacity-1. procedure delete(var item : items); {remove top
In a dynamic stack abstraction when top reaches element from the stack stack and put it in the item}
capacity, we double up the stack size. begin if top = 0 thenstackempty; item :=
stack(top); top := top-1; end; {of delete}
Linked List-based implementation These two procedures are so simple that they
Linked List-based implementation provides the perhaps need no more explanation. Procedure
best (from the efficiency point of view) dynamic delete actually combines the functions TOP and
stack implementation. DELETE, stackfull and stackempty are procedures
which are left unspecified since they will depend
III. QUEUE ITS APPLICATION AND
upon the particular application. Often a stackfull
IMPLEMENTIONS
condition will signal that more storage needs to be
A queue is a container of objects (a linear allocated and the program re-run. Stackempty is
collection) that are inserted and removed according often a meaningful condition.
to the first-in first-out (FIFO) principle. An VI. ADDITION IN QUEUE
excellent example of a queue is a line of students in
procedureaddq (item : items); {add item to the
the food court of the UC. New additions to a line
queue q} begin if rear=n thenqueuefullelse begin
made to the back of the queue, while removal (or
rear :=rear+1; q[rear]:=item; end;end;{of addq}
serving) happens in the front. In the queue only two

IJIRT 101357 INTERNATIONAL JOURNAL OF INNOVATIVE RESEARCH IN TECHNOLOGY 585


© 2014 IJIRT | Volume 1 Issue 7 | ISSN: 2349-6002

VII. DELETION IN QUEUE • Lists are collections of items where each


item holds a relative position.
proceduredeleteq (var item : items);{delete from • A linked list implementation maintains
the front of q and put into item} begin if front = logical order without requiring physical storage
rear thenqueueemptyelse begin front := requirements.
front+1 item := q[front]; end;end; {of deleteq} • Modification to the head of the linked list
is a special case.
VIII. CONCLUSIONS
REFERENCES
• Linear data structures maintain their data
in an ordered fashion. • "Queue (Java Platform SE 7)".
• Stacks are simple data structures that Docs.oracle.com. 2014-03-26. Retrieved 2014-05-
maintain a LIFO, last-in first-out, ordering. 22.
• The fundamental operations for a stack are • Donald Knuth. The Art of Computer
push, pop, and isEmpty. Programming, Volume 1: Fundamental
• Queues are simple data structures that Algorithms, Third Edition. Addison-Wesley, 1997.
maintain a FIFO, first-in first-out, ordering. ISBN 0-201-89683-4. Section 2.2.1: Stacks,
• The fundamental operations for a queue Queues, and Deques, pp. 238–243.
are enqueue, dequeue, and isEmpty • Thomas H. Cormen, Charles E. Leiserson,
• Stacks are very useful for designing Ronald L. Rivest, and Clifford Stein. Introduction
algorithms to evaluate and translate expressions. to Algorithms, Second Edition. MIT Press and
• Stacks can provide a reversal McGraw-Hill, 2001. ISBN 0-262-03293-7. Section
characteristic. 10.1: Stacks and queues, pp. 200–204.
• Queues can assist in the construction of • William Ford, William Topp. Data
timing simulations. Structures with C++ and STL, Second Edition.
• Simulations use random number Prentice Hall, 2002. ISBN 0-13-085850-1. Chapter
generators to create a real-life situation and allow 8: Queues and Priority Queues, pp. 386–390.
• Adam Drozdek. Data Structures and
us to answer “what if” types of questions.
• Deques are data structures that allow Algorithms in C++, Third Edition. Thomson
hybrid behavior like that of stacks and queues. Course Technology, 2005. ISBN 0-534-49182-0.
Chapter 4: Stacks and Queues, pp. 137–169.
• The fundamental operations for a deque
are addFront, addRear, removeFront, removeRear,
and isEmpty.

IJIRT 101357 INTERNATIONAL JOURNAL OF INNOVATIVE RESEARCH IN TECHNOLOGY 586

You might also like