The document discusses stacks and their implementation and use in evaluating arithmetic expressions. It defines a stack as a collection of elements that can only be inserted or removed from one end, called the top. Stacks follow a last-in, first-out (LIFO) principle. Arrays can be used to implement stacks, with a pointer tracking the current top element. Common stack operations like push, pop, peek, etc. are described. Stacks are useful for converting infix expressions to postfix and then evaluating them, as operators are processed after their operands in postfix notation.
The document discusses different implementations of stacks and queues using linked lists and arrays. It describes how stacks can be implemented using a linked list, with push and pop operations adding and removing nodes from the head of the list. Queues can also be implemented with linked lists or arrays, but arrays require additional logic to maintain first-in, first-out order efficiently. Common applications of stacks and queues include evaluating expressions, checking for balanced brackets, and managing tasks in operating systems and server requests.
Data Structure- Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −
PUSH, POP, PEEP
The document describes implementing a queue using an array. It provides algorithms for enQueue() and deQueue() operations. EnQueue() inserts elements at the rear by incrementing rear and checking for full. DeQueue() deletes elements from the front by incrementing front and checking for empty. The queue uses front and rear pointers to manage insertion and deletion of elements based on FIFO principle using an underlying fixed-size array.
1) Stacks are last-in, first-out (LIFO) data structures that allow efficient insertion and removal of elements from only one end, called the top. Common stack operations are push and pop.
2) Stacks have many applications, including checking for balanced brackets in code, evaluating postfix expressions by using intermediate results, and implementing function calls and recursion by saving activation records on a stack.
3) Stacks can be implemented using either a linked list or an array. The array implementation uses an array and a top pointer to track the top of the stack.
The document discusses the stack data structure. A stack is a collection of elements that follow the LIFO (last-in, first-out) principle. Elements can be inserted and removed from the top of the stack only. Stacks have common applications like undo functions in text editors and web browser history. Formally, a stack is an abstract data type that supports push, pop, top, is_empty and length operations. The document provides examples and explanations of stack operations and applications like infix to postfix conversion, expression evaluation, balancing symbols, function calls and reversing a string.
In computer science, a stack is an abstract data type that serves as a collection of elements, with two main principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed.
The document discusses stacks and their implementation and use in evaluating arithmetic expressions. It defines a stack as a collection of elements that can only be inserted or removed from one end, called the top. Stacks follow a last-in, first-out (LIFO) principle. Arrays can be used to implement stacks, with a pointer tracking the current top element. Common stack operations like push, pop, peek, etc. are described. Stacks are useful for converting infix expressions to postfix and then evaluating them, as operators are processed after their operands in postfix notation.
The document discusses different implementations of stacks and queues using linked lists and arrays. It describes how stacks can be implemented using a linked list, with push and pop operations adding and removing nodes from the head of the list. Queues can also be implemented with linked lists or arrays, but arrays require additional logic to maintain first-in, first-out order efficiently. Common applications of stacks and queues include evaluating expressions, checking for balanced brackets, and managing tasks in operating systems and server requests.
Data Structure- Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −
PUSH, POP, PEEP
The document describes implementing a queue using an array. It provides algorithms for enQueue() and deQueue() operations. EnQueue() inserts elements at the rear by incrementing rear and checking for full. DeQueue() deletes elements from the front by incrementing front and checking for empty. The queue uses front and rear pointers to manage insertion and deletion of elements based on FIFO principle using an underlying fixed-size array.
1) Stacks are last-in, first-out (LIFO) data structures that allow efficient insertion and removal of elements from only one end, called the top. Common stack operations are push and pop.
2) Stacks have many applications, including checking for balanced brackets in code, evaluating postfix expressions by using intermediate results, and implementing function calls and recursion by saving activation records on a stack.
3) Stacks can be implemented using either a linked list or an array. The array implementation uses an array and a top pointer to track the top of the stack.
The document discusses the stack data structure. A stack is a collection of elements that follow the LIFO (last-in, first-out) principle. Elements can be inserted and removed from the top of the stack only. Stacks have common applications like undo functions in text editors and web browser history. Formally, a stack is an abstract data type that supports push, pop, top, is_empty and length operations. The document provides examples and explanations of stack operations and applications like infix to postfix conversion, expression evaluation, balancing symbols, function calls and reversing a string.
In computer science, a stack is an abstract data type that serves as a collection of elements, with two main principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed.
https://github.com/ashim888/dataStructureAndAlgorithm
Stack
Concept and Definition
• Primitive Operations
• Stack as an ADT
• Implementing PUSH and POP operation
• Testing for overflow and underflow conditions
Recursion
• Concept and Definition
• Implementation of:
¬ Multiplication of Natural Numbers
¬ Factorial
¬ Fibonacci Sequences
The Tower of Hanoi
This document discusses stacks and queues as data structures. It begins by introducing stacks and their LIFO (last-in, first-out) operation. Common applications of stacks are then described, such as function calls, calculators, mazes, and undo functions. Static and dynamic stack implementations using arrays and linked lists are covered. The document then introduces queues and their FIFO (first-in, first-out) operation. Example applications of queues like print jobs and round robin scheduling are provided. Finally, the operations and implementations of queues are discussed at a high level.
1. The document discusses stacks and their implementation as a data structure. Stacks follow the last-in, first-out (LIFO) principle and can be implemented using either arrays (static implementation) or linked lists (dynamic implementation).
2. Common stack operations like push, pop, peek and isEmpty are described along with their time complexities. Converting expressions from infix to postfix notation using stacks is also covered.
3. Examples of implementing stacks using arrays and linked lists in C programming language are provided, including functions for push, pop and traversal operations. Converting infix expressions to equivalent postfix forms using stack operations is demonstrated through examples.
The document discusses stacks and queues. It defines stacks as LIFO data structures and queues as FIFO data structures. It describes basic stack operations like push and pop and basic queue operations like enqueue and dequeue. It then discusses implementing stacks and queues using arrays and linked lists, outlining the key operations and memory requirements for each implementation.
This document discusses different implementations of stacks and queues using linked lists and arrays. It describes how to implement a stack using a linked list, with push and pop operations adding and removing nodes from the front of the list. Queues are described as first-in first-out data structures, with enqueue adding to the back and dequeue removing from the front. Examples are given of using stacks and queues for applications like balancing parentheses in expressions and evaluating postfix notation.
The document discusses stacks in C++. It defines a stack as a data structure that follows LIFO (Last In First Out) principle where the last element added is the first to be removed. Stacks can be implemented using arrays or linked lists. The key operations on a stack are push which adds an element and pop which removes an element. Example applications of stacks include function call stacks, converting infix to postfix notation, and reversing arrays.
This document discusses stacks, including what they are, their operations, implementations, and applications. Stacks follow LIFO order and can be implemented using arrays or linked lists. Common stack operations are push, pop, peek, isEmpty, and size. Stacks have various applications, including converting expressions between infix, postfix, and prefix notation.
An abstract data type (ADT) is a mathematical model for data structures that defines the type solely by the operations that can be performed on it. For example, a stack ADT can be defined by two operations: push, which inserts an item into the stack, and pop, which removes the top item. Abstract data types are theoretical entities used to simplify algorithm descriptions and formally describe programming language type systems. A stack is a linear data structure that follows the last-in, first-out principle, where items can only be inserted or removed from one end of the stack. Stacks have common applications in arithmetic expression evaluation, backtracking, and function call processing.
The document discusses stacks and their implementation and applications. Stacks are LIFO data structures that can be implemented using arrays. Key operations on stacks include push, pop, peek, isEmpty and isFull. Stacks have various applications including expression evaluation, recursion, function calls and memory management. Stacks can grow either upwards or downwards in the array.
The document discusses stacks and queues as abstract data types. It describes stacks as last-in, first-out (LIFO) data structures that can be implemented using arrays or linked lists. Elements are inserted and removed from one end, called the top. Similarly, queues are first-in, first-out (FIFO) structures where elements are inserted at the rear and removed from the front. Common operations for both include push/enqueue, pop/dequeue, isEmpty, and isFull. Example code demonstrates implementing stacks and queues in C using arrays and linked lists. Applications are given such as undo functions, method call stacks, and waiting lists.
A queue is a data structure that follows the first-in, first-out (FIFO) principle. Elements are added to the rear of the queue and removed from the front. A queue can be implemented using an array, with indexes to track the front and rear elements. When an element is added (enqueued), the rear index is incremented; when an element is removed (dequeued), the front index is incremented and the element at that index is returned. The queue has a limited capacity based on the size of the array.
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
This document discusses stacks as a data structure. It defines a stack as a Last In First Out (LIFO) structure where the last item inserted is the first out. Key stack operations like push, pop, peek and isEmpty are described. Examples of stack applications include checking for balanced brackets, converting infix to postfix notation, implementing an undo/redo feature and recursion. The document also provides pseudocode for converting an infix expression to postfix using a stack and describes how a postfix calculator evaluates expressions.
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
Explain Stack and its Concepts, Its Operations, Queue, Circular Queue, Priority Queue. Explain Queue and It's Operations
Data Structures, Abstract Data Types
The document discusses stacks and queues as data structures. It defines a stack as a linear data structure that follows the LIFO principle with insertion and deletion occurring at one end. Key stack operations are described as push, pop, peek, isEmpty and isFull. Queue is defined as a linear structure that follows the FIFO principle with insertion at the rear and deletion at the front. Common queue operations are enqueue, dequeue, peek, isEmpty and isFull. Array and linked list implementations of stacks and queues are also covered.
The document discusses stacks and their implementation. It introduces stacks and their common operations like push and pop. It describes using stacks to solve problems like reversing a list, calculating in Reverse Polish Notation, and bracket matching by keeping track of opening brackets on a stack. Sample code is provided to implement a stack class with methods like push, pop and top to manipulate items on the stack.
The document discusses stacks and their properties. It defines a stack as a linear data structure where items are inserted and deleted from one end, following the LIFO (last in, first out) principle. Stacks are commonly used in computer systems for tasks like compiler operations and process scheduling. The key stack operations are push to insert an item and pop to remove the top item.
The document discusses stacks and stack operations in C. It defines a stack as a linear data structure that follows the LIFO principle, where elements are added and removed from one end called the top. The key stack operations are PUSH to add an element, POP to remove an element, and DISPLAY to output the stack. It provides algorithms for implementing PUSH and POP and handling exceptions like stack overflow. The document also covers postfix notation, where operators follow operands, and the postfix evaluation algorithm using a stack.
https://github.com/ashim888/dataStructureAndAlgorithm
Stack
Concept and Definition
• Primitive Operations
• Stack as an ADT
• Implementing PUSH and POP operation
• Testing for overflow and underflow conditions
Recursion
• Concept and Definition
• Implementation of:
¬ Multiplication of Natural Numbers
¬ Factorial
¬ Fibonacci Sequences
The Tower of Hanoi
This document discusses stacks and queues as data structures. It begins by introducing stacks and their LIFO (last-in, first-out) operation. Common applications of stacks are then described, such as function calls, calculators, mazes, and undo functions. Static and dynamic stack implementations using arrays and linked lists are covered. The document then introduces queues and their FIFO (first-in, first-out) operation. Example applications of queues like print jobs and round robin scheduling are provided. Finally, the operations and implementations of queues are discussed at a high level.
1. The document discusses stacks and their implementation as a data structure. Stacks follow the last-in, first-out (LIFO) principle and can be implemented using either arrays (static implementation) or linked lists (dynamic implementation).
2. Common stack operations like push, pop, peek and isEmpty are described along with their time complexities. Converting expressions from infix to postfix notation using stacks is also covered.
3. Examples of implementing stacks using arrays and linked lists in C programming language are provided, including functions for push, pop and traversal operations. Converting infix expressions to equivalent postfix forms using stack operations is demonstrated through examples.
The document discusses stacks and queues. It defines stacks as LIFO data structures and queues as FIFO data structures. It describes basic stack operations like push and pop and basic queue operations like enqueue and dequeue. It then discusses implementing stacks and queues using arrays and linked lists, outlining the key operations and memory requirements for each implementation.
This document discusses different implementations of stacks and queues using linked lists and arrays. It describes how to implement a stack using a linked list, with push and pop operations adding and removing nodes from the front of the list. Queues are described as first-in first-out data structures, with enqueue adding to the back and dequeue removing from the front. Examples are given of using stacks and queues for applications like balancing parentheses in expressions and evaluating postfix notation.
The document discusses stacks in C++. It defines a stack as a data structure that follows LIFO (Last In First Out) principle where the last element added is the first to be removed. Stacks can be implemented using arrays or linked lists. The key operations on a stack are push which adds an element and pop which removes an element. Example applications of stacks include function call stacks, converting infix to postfix notation, and reversing arrays.
This document discusses stacks, including what they are, their operations, implementations, and applications. Stacks follow LIFO order and can be implemented using arrays or linked lists. Common stack operations are push, pop, peek, isEmpty, and size. Stacks have various applications, including converting expressions between infix, postfix, and prefix notation.
An abstract data type (ADT) is a mathematical model for data structures that defines the type solely by the operations that can be performed on it. For example, a stack ADT can be defined by two operations: push, which inserts an item into the stack, and pop, which removes the top item. Abstract data types are theoretical entities used to simplify algorithm descriptions and formally describe programming language type systems. A stack is a linear data structure that follows the last-in, first-out principle, where items can only be inserted or removed from one end of the stack. Stacks have common applications in arithmetic expression evaluation, backtracking, and function call processing.
The document discusses stacks and their implementation and applications. Stacks are LIFO data structures that can be implemented using arrays. Key operations on stacks include push, pop, peek, isEmpty and isFull. Stacks have various applications including expression evaluation, recursion, function calls and memory management. Stacks can grow either upwards or downwards in the array.
The document discusses stacks and queues as abstract data types. It describes stacks as last-in, first-out (LIFO) data structures that can be implemented using arrays or linked lists. Elements are inserted and removed from one end, called the top. Similarly, queues are first-in, first-out (FIFO) structures where elements are inserted at the rear and removed from the front. Common operations for both include push/enqueue, pop/dequeue, isEmpty, and isFull. Example code demonstrates implementing stacks and queues in C using arrays and linked lists. Applications are given such as undo functions, method call stacks, and waiting lists.
A queue is a data structure that follows the first-in, first-out (FIFO) principle. Elements are added to the rear of the queue and removed from the front. A queue can be implemented using an array, with indexes to track the front and rear elements. When an element is added (enqueued), the rear index is incremented; when an element is removed (dequeued), the front index is incremented and the element at that index is returned. The queue has a limited capacity based on the size of the array.
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
This document discusses stacks as a data structure. It defines a stack as a Last In First Out (LIFO) structure where the last item inserted is the first out. Key stack operations like push, pop, peek and isEmpty are described. Examples of stack applications include checking for balanced brackets, converting infix to postfix notation, implementing an undo/redo feature and recursion. The document also provides pseudocode for converting an infix expression to postfix using a stack and describes how a postfix calculator evaluates expressions.
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
Explain Stack and its Concepts, Its Operations, Queue, Circular Queue, Priority Queue. Explain Queue and It's Operations
Data Structures, Abstract Data Types
The document discusses stacks and queues as data structures. It defines a stack as a linear data structure that follows the LIFO principle with insertion and deletion occurring at one end. Key stack operations are described as push, pop, peek, isEmpty and isFull. Queue is defined as a linear structure that follows the FIFO principle with insertion at the rear and deletion at the front. Common queue operations are enqueue, dequeue, peek, isEmpty and isFull. Array and linked list implementations of stacks and queues are also covered.
The document discusses stacks and their implementation. It introduces stacks and their common operations like push and pop. It describes using stacks to solve problems like reversing a list, calculating in Reverse Polish Notation, and bracket matching by keeping track of opening brackets on a stack. Sample code is provided to implement a stack class with methods like push, pop and top to manipulate items on the stack.
The document discusses stacks and their properties. It defines a stack as a linear data structure where items are inserted and deleted from one end, following the LIFO (last in, first out) principle. Stacks are commonly used in computer systems for tasks like compiler operations and process scheduling. The key stack operations are push to insert an item and pop to remove the top item.
The document discusses stacks and stack operations in C. It defines a stack as a linear data structure that follows the LIFO principle, where elements are added and removed from one end called the top. The key stack operations are PUSH to add an element, POP to remove an element, and DISPLAY to output the stack. It provides algorithms for implementing PUSH and POP and handling exceptions like stack overflow. The document also covers postfix notation, where operators follow operands, and the postfix evaluation algorithm using a stack.
Similar to lecture10trsgfchjvxgfzfdchgdchgcgshyjh.ppt (20)
Kinetic studies on malachite green dye adsorption from aqueous solutions by A...Open Access Research Paper
Water polluted by dyestuffs compounds is a global threat to health and the environment; accordingly, we prepared a green novel sorbent chemical and Physical system from an algae, chitosan and chitosan nanoparticle and impregnated with algae with chitosan nanocomposite for the sorption of Malachite green dye from water. The algae with chitosan nanocomposite by a simple method and used as a recyclable and effective adsorbent for the removal of malachite green dye from aqueous solutions. Algae, chitosan, chitosan nanoparticle and algae with chitosan nanocomposite were characterized using different physicochemical methods. The functional groups and chemical compounds found in algae, chitosan, chitosan algae, chitosan nanoparticle, and chitosan nanoparticle with algae were identified using FTIR, SEM, and TGADTA/DTG techniques. The optimal adsorption conditions, different dosages, pH and Temperature the amount of algae with chitosan nanocomposite were determined. At optimized conditions and the batch equilibrium studies more than 99% of the dye was removed. The adsorption process data matched well kinetics showed that the reaction order for dye varied with pseudo-first order and pseudo-second order. Furthermore, the maximum adsorption capacity of the algae with chitosan nanocomposite toward malachite green dye reached as high as 15.5mg/g, respectively. Finally, multiple times reusing of algae with chitosan nanocomposite and removing dye from a real wastewater has made it a promising and attractive option for further practical applications.
Evolving Lifecycles with High Resolution Site Characterization (HRSC) and 3-D...Joshua Orris
The incorporation of a 3DCSM and completion of HRSC provided a tool for enhanced, data-driven, decisions to support a change in remediation closure strategies. Currently, an approved pilot study has been obtained to shut-down the remediation systems (ISCO, P&T) and conduct a hydraulic study under non-pumping conditions. A separate micro-biological bench scale treatability study was competed that yielded positive results for an emerging innovative technology. As a result, a field pilot study has commenced with results expected in nine-twelve months. With the results of the hydraulic study, field pilot studies and an updated risk assessment leading site monitoring optimization cost lifecycle savings upwards of $15MM towards an alternatively evolved best available technology remediation closure strategy.
Improving the viability of probiotics by encapsulation methods for developmen...Open Access Research Paper
The popularity of functional foods among scientists and common people has been increasing day by day. Awareness and modernization make the consumer think better regarding food and nutrition. Now a day’s individual knows very well about the relation between food consumption and disease prevalence. Humans have a diversity of microbes in the gut that together form the gut microflora. Probiotics are the health-promoting live microbial cells improve host health through gut and brain connection and fighting against harmful bacteria. Bifidobacterium and Lactobacillus are the two bacterial genera which are considered to be probiotic. These good bacteria are facing challenges of viability. There are so many factors such as sensitivity to heat, pH, acidity, osmotic effect, mechanical shear, chemical components, freezing and storage time as well which affects the viability of probiotics in the dairy food matrix as well as in the gut. Multiple efforts have been done in the past and ongoing in present for these beneficial microbial population stability until their destination in the gut. One of a useful technique known as microencapsulation makes the probiotic effective in the diversified conditions and maintain these microbe’s community to the optimum level for achieving targeted benefits. Dairy products are found to be an ideal vehicle for probiotic incorporation. It has been seen that the encapsulated microbial cells show higher viability than the free cells in different processing and storage conditions as well as against bile salts in the gut. They make the food functional when incorporated, without affecting the product sensory characteristics.
Optimizing Post Remediation Groundwater Performance with Enhanced Microbiolog...Joshua Orris
Results of geophysics and pneumatic injection pilot tests during 2003 – 2007 yielded significant positive results for injection delivery design and contaminant mass treatment, resulting in permanent shut-down of an existing groundwater Pump & Treat system.
Accessible source areas were subsequently removed (2011) by soil excavation and treated with the placement of Emulsified Vegetable Oil EVO and zero-valent iron ZVI to accelerate treatment of impacted groundwater in overburden and weathered fractured bedrock. Post pilot test and post remediation groundwater monitoring has included analyses of CVOCs, organic fatty acids, dissolved gases and QuantArray® -Chlor to quantify key microorganisms (e.g., Dehalococcoides, Dehalobacter, etc.) and functional genes (e.g., vinyl chloride reductase, methane monooxygenase, etc.) to assess potential for reductive dechlorination and aerobic cometabolism of CVOCs.
In 2022, the first commercial application of MetaArray™ was performed at the site. MetaArray™ utilizes statistical analysis, such as principal component analysis and multivariate analysis to provide evidence that reductive dechlorination is active or even that it is slowing. This creates actionable data allowing users to save money by making important site management decisions earlier.
The results of the MetaArray™ analysis’ support vector machine (SVM) identified groundwater monitoring wells with a 80% confidence that were characterized as either Limited for Reductive Decholorination or had a High Reductive Reduction Dechlorination potential. The results of MetaArray™ will be used to further optimize the site’s post remediation monitoring program for monitored natural attenuation.
REPORT-PRESENTATION BY CHIEF SECRETARY, ANDAMAN NICOBAR ADMINISTRATION IN OA ...
lecture10trsgfchjvxgfzfdchgdchgcgshyjh.ppt
1. Stacks
• Objective
After this lecture you will be able to:
• Describe a stack
• Describe the representation of stack using linear
array
• Describe the representation of stack using linear
linked list
• Implementation of various operations on stack
• Describe some applications of stacks
2. Stack
• Stack is one of the commonly used data
structures.
• Stack is also called last in first out (LIFO)
system
• Stack is a linear list in which insertion and
deletion can take place only at one end
called top.
• This structure operates in much the same
way as stack of trays.
4. •The following figure illustrate a stack, which can
accommodate maximum of 10 elements
figure shows stack after pushing elements 8,10,12,-5,6
6
-5
12
10
8
0
1
2
3
4
5
6
7
8
9
top
6. stack after pushing elements 8,10,12,-5,6,9,55
55
9
6
-5
12
10
8
0
1
2
3
4
5
6
7
8
9
top
7. Operations on stacks
• Createstack(s)—to create s as an empty stack
• Push(s,i)--to push elementi onto stack s.
• Pop(s)—to access and remove the top element
of the stack s
• Peek(s)—to access the top element of the
stacks without removing it from the stack s.
• Isfull(s)—to check whether the stack s is full
• isempty—to check whether the stack s is
empty
8. Representation of stack in
memory
• Representation of stack using array:
Suppose elements of the stack are integer type and stack can
store maximum 10 elements..
#define MAX 10
typedef struct
{
int top;
int elements[MAX];
}stack;
stack s;
• Here we have defined our own data type named stack.
• First element top will be used to index top element
• Array elements hold the elements of the stack
• Last line declares variable s of type stack
9. stack
• In addition to the previous declaration, we
will use the declaration
typedef enum {false, true } Boolean;
This statement defined new data type
named Boolean which can take value false
or true.
11. Creating an empty stack
• Before we can use a stack, it is to be initialized.
• As the index of array elements can take any value in the
range 0 to MAX-1, the purpose of initializing the stack is
served by assigning value -1 to the top of variable.
• This simple task can be accomplished by the following
function.
Void createstack( stack *ps)
{
ps=-1;
}
12. Testing stack for underflow
Boolean isempty(stack *ps)
{
if(ps->top==-1)
return true;
else
return false;
}
or
Boolean is empty(stack *ps)
{
return ((ps->top==-1)?true:false);
}
13. Testing stack for overflow
Boolean isfull(stack *ps)
{
if(ps->top==MAX-1)
return true;
else
return false;
}
or
Boolean is empty(stack *ps)
{
return ((ps->top==MAX-1)?true:false);
}
14. Push Operation
Before the push operation, if the stack is empty, then the
value of the top will be -1and if the stack is not empty
then the value of the top will be the index of the element
currently on the top.
Therefore we place the value onto the stack, the value of
top is incremented so that it points to the new top of
stack, where incoming element is placed.
Void push(stack *ps, int value)
{
ps->top++;
ps->elements[ps->top]=value;
}
15. Pop Operation
The element on the top of the stack is assigned to a local variable,
which later on will be returned via the return statement.
After assigning the top element to a local variable, the variable top is
decremented so that it points to a new top
Int pop(stack *ps)
{
int temp;
temp=ps->elements[ps->top];
ps->top--;
return temp;
}
16. Accessing top element
There may be instances where we want to
access the top element of the stack
without removing it from the stack.
Int peek( stack *ps)
{
return(ps->elements[ps->top]);
}
17. Representing a stack using a linked
list
A stack represented using a linked list is also known as
linked stack.
The array based representation of stack suffers from
following limitations.
• Size of the stack must be known in advance
• We may come across situation when an attempt to push
an element causes overflow.
However stack is an abstract data structure can not be full.
Hence, abstractly, it is always possible to push an
element onto stack. Therefore stack as an array prohibits
the growth of the stack beyond the finite number of
elements.
18. Declaration of stack
The linked list representation allows a stack to grow to a
limit of the computer’s memory.
Typedef struct nodetype
{
int info;
struct nodetype *next;
}stack;
Stack *top;
Here I have defined my own data type named stack,
which is a self referential structure and whose first
element info hold the element of the stack and the
second element next hold the address of the element
under it in the stack.
The last line declares a pointer variable top of type
stack.
20. Creating an empty stack
Before we can use a stack, it is to be initialized.
To initialize a stack, we will create an empty
linked list.
The empty linked list is created by setting pointer
variable top to value NULL.
Void createstack(stack **top)
{
*top=NULL;
}
21. Testing stack for underflow
Boolean isempty(stack *top)
{
if(top==NULL)
return true;
else
return false;
}
or
Boolean is empty(stack *top)
{
return ((top==NULL)?true:false);
}
22. Testing stack for overflow
Since stack represented using a linked list
can grow to a limit of computers memory,
there overflow condition never occurs.
Hence this operation is not implemented
for linked list.
23. Push operation
To push a new element onto the stack, the element is inserted in
the beginning of the linked list.
void push(stack **top, int value)
{
stack *ptr;
ptr=(stack*)malloc(sizeof(stack));
if(ptr==NULL)
{
printf(“n unable to allocate memory for new node…”);
printf(“npress any key to exit..”);
getch();
return;
}
ptr->info=value;
ptr->next=*top;
*top=ptr;
}
24. Pop operation
To pop an element from the stack, the element is removed
from the beginning of the linked list.
Int pop(stack **top)
{
int temp;
stack *ptr;
temp=(*top)->info;
ptr=*top;
*top=(*top)->next;
free(ptr);
return temp;
}
26. Dispose a stack
Because the stack is implemented using linked lists,
therefore it is programmers job to write the code to
release the memory occupied by the stack.
Void disposestack(stack **top)
{
stack *ptr;
while(*top!=NULL)
{
ptr=*top;
*top=(*top)->next;
free(ptr);
}
}
27. Applications of Stacks
• Stacks are used to pass parameters between
functions. On a call to function, parameter and local
variables are stored on stack.
• High level programming languages, such as Pascal
c etc. that provide support for recursion use stack
for book keeping. In each recursive call, there is
need to save the current values of parameters, local
variables and the return address.
In addition to above stack are used to solve the various
problems….
1. Parenthesis checker
2. Mathematical notation translation
1. Polish (prefix) notation
2. Reverse polish (postfix) Notation
3. Quick sort algorithm
28. Parenthesis checker
• Parenthesis checker is a program that checks
whether a mathematical expression is properly
parenthesized.
• We will consider three sets of grouping symbols:
– The standard parenthesis ”( )”
– The braces “{ }”
– the brackets “[ ]”
For an input expression, it verifies that for each left
parenthesis, braces or racket, there is a corresponding
closing symbol and the symbols are appropriately nested.
30. Mathematical notation
Translation
Symbol used Operation
performed
Precedence
* (asterisk) Multiplication Highest
/ (slash) Division Highest
% (percentage) Modulus Highest
+ (plus) Addition Lowest
- (hyphen) subtraction lowest
31. Infix notation
In this notation, the operator symbol is placed
between its two operands.
• To add A to B we can write as A+B or B+A
• To subtract D from C we write as C-D, but we
can not write D-C as this operation is not
commutative.
In this notation we must distinguish between
(A+B)/C and A+(B/C)
32. Polish (prefix) notation
In this notation, named after the polish
mathematician Jan Lukasiewiez, the operator
symbol is placed before its two operands.
• To add A to B we write as +AB or +BA
• To subtract D from C we have to writ as –CD
not as -DC
33. Infix to polish notation
In order to translate an arithmetic expression in infix notation to
polish notation, we do step by step using rackets ([]) to indicate
the partial translations.
• Consider the following expression in infix notation:
(A-B/C)*(A*K-L)
The partial translation may look like:
(A-[/BC])*([*AK]-L)
[-A/BC]*[-*AKL]
*-A/BC-*AKL
The fundamental property of polish notation is that the order in
which the operations to perform is completely determined by
the position of the operators and operands in the expression.
Accordingly one never needs parenthesis when writing expression
in polish notation.
34. Reverse Polish (Postfix) Notation
In this notation the operator symbol is placed
after its two operands.
• To add A to B we can write as AB+ or BA+
• To subtract D from C we have to write as CD-
not as DC-.
35. Infix to reverse polish notation
Consider the following expression in infix
notation:
(A-B/C)*(A/K-L)
The partial translation may look like:]
(A-[BC/])*([AK/]-L)
[ABC/-]*[AK/L-]
ABC/-AK/L-*
36. Evaluating Mathematical
Expressions
Generally we use infix notation, where one can not tell the
order in which the operator should be applied by looking
at the expression.
The expression in postfix notation is very easy to evaluate,
as the operands appear before the operator, there is no
need of operator precedence or parentheses for
operation.
In order to evaluate a postfix expression it is scanned from
left to right.
As operands are encountered, they are pushed on a stack.
When an operator encountered, pop top one or two
operands depending on the operator, perform the
operation and place the result back on the stack.