SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Stacks ,[object Object],[object Object]
 
Stacks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stacks – Array Implementation ,[object Object],[object Object],[object Object]
Growing Downwards   Initial state: stk_ptr = MAX - 1   6 5 4 3 2 1 0 7 8 9 ,[object Object],[object Object],6 8 3 12 ,[object Object]
Growing Downwards   Initial state: stk_ptr = MAX   6 8 3 12 6 5 4 3 2 1 0 7 8 9 ,[object Object],[object Object],[object Object]
Growing Upwards   Initial state: stk_ptr = 0   6 4 5 2 7 6 5 4 3 2 1 0 7 8 9 ,[object Object],[object Object],[object Object]
Growing Upwards   Initial state: stk_ptr = -1   6 4 5 2 7 6 5 4 3 2 1 0 7 8 9 ,[object Object],[object Object],[object Object]
Stacks – Array Implementation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
bool Stack::push(int n)‏ { if (! isFull() ) {  stackArray[stk_ptr] = n;  stk_ptr = stk_ptr + 1; return true;  } else return false; } bool Stack::pop(int &n)‏ { if (! IsEmpty ()) {  stk_ptr = stk_ptr – 1; n = stackArray[stk_ptr];  return true;  } else return false; } bool Stack::isEmpty()‏ {  return (stk_ptr == 0);  } Stack::Stack(int s)‏ { maxSize = s; stk_ptr = 0; stackArray = new int[maxSize]; } bool Stack::isFull()‏ {  return (stk_ptr == maxSize);  }
Applications of stack ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Multiple Stack ,[object Object],[object Object],[object Object],[object Object]
Queues ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Uses of Queue ,[object Object],[object Object],[object Object],[object Object],[object Object]
Queues – Array Implementation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Circular Implementation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],0 1 2 3 MS-1
Circular Implementation bool Queue::remove(int &n)‏ { if (! isEmpty() {  n = QueueArray[front];  front++; if (front == maxSize)  front = 0; size--; return true;  } else return false; } 0 1 2 3 MS-1
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],bool Queue::isFull()  {return size == MaxSize;} bool Queue::isEmpty()  {return size == 0; } Queue::Queue(int s)‏ { if (s <= 0) MaxSize = 10; else MaxSize = s; QueueArray = new int[MaxSize]; size = 0;  rear = 0; front = 0; } bool Queue::remove(int &n)‏ { if (! isEmpty() ) {  n = QueueArray[rear];  front++; if (front == maxSize)  front = 0;  size--; return true;  } else return false; } 0 1 2 3 MS-1
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],bool Queue::remove(int &n)‏ { if (! isEmpty() {  n = QueueArray[front];  front++; if (front == maxSize)  front = 0; size--; return true;  } else return false; } Add: rear = (rear + 1) % maxSize;   Remove: front = (front + 1) % maxSize;   What happens if we try to do it clockwise? 0 1 2 3 MS-1
Double Ended Queue (Dequeue)  ,[object Object],[object Object],[object Object],[object Object]
Input restricted dequeue (algorithm) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Output restricted dequeue (algorithm) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Priority Queue ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Applications of Stacks  Evaluation of Expression ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algorithm to Evaluate fully Parenthesized Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluation of Fully Parenthesized Expression (a+(b/c)) Assuming a=2, b=6, c=3 Pop”(a+2” and evaluate and push the result back 4 )‏ Pop”(b/c” and evaluate and push the result back (a+2 )‏ Push (a+(b/c c push (a+(b/ / push (a+(b b push (a+( ( push (a+ + push (a a Push ( ( Remarks Stack Input Symbol
Evaluation of Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object]
INFIX and POSTFIX abc/eg+*+h+fi*- a+b/c*(e+g)+h-f*i ab/c-de*+ac*- a/b-c+d*e-a*c ab+cd+*e/f- (a+b)*(c+d)/e-f ab*cd*+ a*b+c*d abc*+ a+b*c Postfix Infix
Algorithm to Evaluate Expressions in RPN ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algorithm to Evaluate Expressions in RPN (a+b)*(c+d)    ab+cd+* Assuming a=2, b=6, c=3, d=-1 Pop 8 and 2 from the stack, multiply, and push the result back. Since this is end of the expression, hence it is the final result. 16 * Pop c and d from the stack, add, and push the result back 8  2 + Push 8  c  d d Push 8  c c Pop a and b from the stack, add, and push the result back 8 + Push a  b b Push a a Remarks Stack Input Symbol
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Algorithm for Infix to RPN Conversion
Converting Infix to RPN (a+b)*(c+d)    ab+cd+* Pop remaining symbols from the stack and display RPN    a b + c d + * End of input Pop till “(” is found and display – RPN    a b + c d + * )‏ Operand – display – RPN    a b + c d * ( + d Push as + has higher precedence than ( * ( + + Operand – display – RPN    a b + c * ( c Push  * ( ( Push as stack is empty * * Pop till “(” is found and display – RPN    a b + )‏ Operand – display – RPN    a b ( + b Push as + has higher precedence than ( ( + + Operand – display – RPN    a ( a Push ( ( Remarks Stack Input Symbol
a+b*c/(d+e)    a b c * d e + / +  Pop till “(” is found – RPN    a b c * d e + + / )‏ Pop remaining symbols from the stack and display RPN    a b c * d e + / + End of input Operand – display – RPN    a b c * d e + / ( + e Push as + has higher precedence than ( + / ( + + Operand – display – RPN    a b c * d + / ( d Push  + / ( ( Pop * and push / as * and / have the same precedence but / has higher precedence than +  – RPN    a b c * + / / Operand – display – RPN    a b c + * c Push as * has higher precedence than + + * * Operand – display – RPN    a b + b Push as stack is empty + + Operand – display – RPN    a a Remarks Stack Input Symbol
Use of Stack in the Implementation of Subprograms  ,[object Object],[object Object],[object Object],[object Object]
Activation Records ,[object Object],[object Object],[object Object],[object Object]
Activation Records
Recursive Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Recursion – Some Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How Does Recursion Work Some More Recursive Functions and Their Simulation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simulation of factorial(4)‏ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],n = 4 1. 2. 3. 4. n = 3 1. 2. 3. 4. n = 2 1. 2. 3. 4. n = 1 1. 2. return 1 temp = 1 5. return 2*1 1. 2. return 1 temp = 2 5. return 3*2 1. 2. return 1 temp = 6 5. return 4*6 1. 2. return 1
Fibonacci Sequence 0,1,1,2,3,5,8,13,… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simulation of fibonacci(4)‏ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],n = 2 ,[object Object],[object Object],n = 4 1. 2. 3. n = 3 1. 2. 3. temp1 = 1 4. 1. 2. return 1 n = 1 1. 2.  return 1 temp2 = 1 5. return 2 1. 2. return 1 temp1 = 2 4. 1. 2. return 1 n = 2 1. 2.  return 1 temp2 = 1 5. return 3 1. 2. return 1
Tower of Honoi ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
From Using To 3 Disks ,[object Object],[object Object]
Tower of Honoi Recursive Solution ,[object Object],[object Object]
Tower of Honoi ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simulation of  TOH(1, 2, 3, 3)‏ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],1 2 3 from:1, to:2, using:3, n:3 f = 1, t = 2, u = 3,  n = 3 statement: 3 f = 1, t = 2, u = 3,  n = 1 statement: 3 f = 1, t = 3, u = 2,  n = 2 statement: 3 f = 1, t = 3, u = 2,  n = 0 statement: 1 f = 1, t = 2, u = 3,  n = 1 statement: 4 f = 1, t = 2, u = 3,  n = 1 statement: 5 f = 3, t = 2, u = 1,  n = 0 statement: 1 f = 1, t = 3, u = 2,  n = 2 statement: 4 f = 1, t = 3, u = 2,  n = 2 statement: 5 f = 2, t = 3, u = 1,  n = 1 statement: 3 f = 2, t = 1, u = 3,  n = 0 statement: 1 f = 2, t = 3, u = 1,  n = 1 statement: 4 f = 2, t = 3, u = 1,  n = 1 statement: 5 f = 1, t = 3, u = 2,  n = 0 statement: 1 f = 1, t = 2, u = 3,  n = 3 statement: 4 f = 1, t = 2, u = 3,  n = 3 statement: 5 f = 3, t = 2, u = 1,  n = 2 statement: 3 f = 3, t = 1, u = 2,  n = 1 statement: 3 f = 3, t = 2, u = 1,  n = 0 statement: 3 f = 3, t = 1, u = 2,  n = 1 statement: 4 f = 3, t = 1, u = 2,  n = 1 statement: 5 f = 2, t = 1, u = 3,  n = 0 statement: 1 f = 3, t = 2, u = 1,  n = 2 statement: 4 f = 3, t = 2, u = 1,  n = 2 statement: 5 f = 1, t = 2, u = 3,  n = 1 statement: 3 f = 1, t = 3, u = 2,  n = 0 statement: 1 f = 1, t = 2, u = 3,  n = 1 statement: 4 f = 3, t = 2, u = 1,  n = 1 statement: 5 f = 1, t = 2, u = 3,  n = 0 statement: 5

Weitere ähnliche Inhalte

Was ist angesagt? (19)

Stack
StackStack
Stack
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Stacks
StacksStacks
Stacks
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Stack
StackStack
Stack
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Stack
StackStack
Stack
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Stack application
Stack applicationStack application
Stack application
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 

Andere mochten auch

Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 
It 405 materi 2 java dasar
It 405 materi 2   java dasarIt 405 materi 2   java dasar
It 405 materi 2 java dasarAyi Purbasari
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniquesfika sweety
 
The Landbank's Role in Driving Redevelopment, UC DAAP by Chris Recht
The Landbank's Role in Driving Redevelopment, UC DAAP by Chris RechtThe Landbank's Role in Driving Redevelopment, UC DAAP by Chris Recht
The Landbank's Role in Driving Redevelopment, UC DAAP by Chris RechtThe Port
 
SAP_Business_Object_Professional
SAP_Business_Object_ProfessionalSAP_Business_Object_Professional
SAP_Business_Object_ProfessionalKapil Verma
 
Global leader in real-time clearing
Global leader in real-time clearingGlobal leader in real-time clearing
Global leader in real-time clearingCinnober
 
PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012Arun Gupta
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programmingTOPS Technologies
 
Developing With JAAS
Developing With JAASDeveloping With JAAS
Developing With JAASrahmed_sct
 
C and data structure
C and data structureC and data structure
C and data structureprabhatjon
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structurepcnmtutorials
 
Static Analysis Primer
Static Analysis PrimerStatic Analysis Primer
Static Analysis PrimerCoverity
 

Andere mochten auch (20)

Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Linked list
Linked listLinked list
Linked list
 
Stacks
StacksStacks
Stacks
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
It 405 materi 2 java dasar
It 405 materi 2   java dasarIt 405 materi 2   java dasar
It 405 materi 2 java dasar
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
 
The Landbank's Role in Driving Redevelopment, UC DAAP by Chris Recht
The Landbank's Role in Driving Redevelopment, UC DAAP by Chris RechtThe Landbank's Role in Driving Redevelopment, UC DAAP by Chris Recht
The Landbank's Role in Driving Redevelopment, UC DAAP by Chris Recht
 
SAP_Business_Object_Professional
SAP_Business_Object_ProfessionalSAP_Business_Object_Professional
SAP_Business_Object_Professional
 
Core & advanced java classes in mumbai
Core & advanced java classes in mumbaiCore & advanced java classes in mumbai
Core & advanced java classes in mumbai
 
Global leader in real-time clearing
Global leader in real-time clearingGlobal leader in real-time clearing
Global leader in real-time clearing
 
PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 
Developing With JAAS
Developing With JAASDeveloping With JAAS
Developing With JAAS
 
C and data structure
C and data structureC and data structure
C and data structure
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
 
Static Analysis Primer
Static Analysis PrimerStatic Analysis Primer
Static Analysis Primer
 

Ähnlich wie 03 stacks and_queues_using_arrays

Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptxSonaPathak4
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبياناتRafal Edward
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queueRajkiran Nadar
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptxsinghprpg
 

Ähnlich wie 03 stacks and_queues_using_arrays (20)

Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Lect-28-Stack-Queue.ppt
Lect-28-Stack-Queue.pptLect-28-Stack-Queue.ppt
Lect-28-Stack-Queue.ppt
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
data structure
data structuredata structure
data structure
 
04 stacks
04 stacks04 stacks
04 stacks
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
 
05 queues
05 queues05 queues
05 queues
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Lecture2
Lecture2Lecture2
Lecture2
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 

Mehr von tameemyousaf

Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)tameemyousaf
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)tameemyousaf
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)tameemyousaf
 
Switching Techniques
Switching TechniquesSwitching Techniques
Switching Techniquestameemyousaf
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Controltameemyousaf
 
Workgroup vs domain
Workgroup vs domainWorkgroup vs domain
Workgroup vs domaintameemyousaf
 
Windows server 2003_r2
Windows server 2003_r2Windows server 2003_r2
Windows server 2003_r2tameemyousaf
 
Active directory installation windows 2003 1
Active directory installation windows 2003 1Active directory installation windows 2003 1
Active directory installation windows 2003 1tameemyousaf
 

Mehr von tameemyousaf (12)

Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
 
IP addressing
IP addressingIP addressing
IP addressing
 
Switching Techniques
Switching TechniquesSwitching Techniques
Switching Techniques
 
IP addressing
IP addressingIP addressing
IP addressing
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Control
 
Dhcp
DhcpDhcp
Dhcp
 
Workgroup vs domain
Workgroup vs domainWorkgroup vs domain
Workgroup vs domain
 
Windows server 2003_r2
Windows server 2003_r2Windows server 2003_r2
Windows server 2003_r2
 
Dhcp
DhcpDhcp
Dhcp
 
Active directory installation windows 2003 1
Active directory installation windows 2003 1Active directory installation windows 2003 1
Active directory installation windows 2003 1
 

03 stacks and_queues_using_arrays

  • 1.
  • 2.  
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. bool Stack::push(int n)‏ { if (! isFull() ) { stackArray[stk_ptr] = n; stk_ptr = stk_ptr + 1; return true; } else return false; } bool Stack::pop(int &n)‏ { if (! IsEmpty ()) { stk_ptr = stk_ptr – 1; n = stackArray[stk_ptr]; return true; } else return false; } bool Stack::isEmpty()‏ { return (stk_ptr == 0); } Stack::Stack(int s)‏ { maxSize = s; stk_ptr = 0; stackArray = new int[maxSize]; } bool Stack::isFull()‏ { return (stk_ptr == maxSize); }
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Circular Implementation bool Queue::remove(int &n)‏ { if (! isEmpty() { n = QueueArray[front]; front++; if (front == maxSize) front = 0; size--; return true; } else return false; } 0 1 2 3 MS-1
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Evaluation of Fully Parenthesized Expression (a+(b/c)) Assuming a=2, b=6, c=3 Pop”(a+2” and evaluate and push the result back 4 )‏ Pop”(b/c” and evaluate and push the result back (a+2 )‏ Push (a+(b/c c push (a+(b/ / push (a+(b b push (a+( ( push (a+ + push (a a Push ( ( Remarks Stack Input Symbol
  • 32.
  • 33. INFIX and POSTFIX abc/eg+*+h+fi*- a+b/c*(e+g)+h-f*i ab/c-de*+ac*- a/b-c+d*e-a*c ab+cd+*e/f- (a+b)*(c+d)/e-f ab*cd*+ a*b+c*d abc*+ a+b*c Postfix Infix
  • 34.
  • 35. Algorithm to Evaluate Expressions in RPN (a+b)*(c+d)  ab+cd+* Assuming a=2, b=6, c=3, d=-1 Pop 8 and 2 from the stack, multiply, and push the result back. Since this is end of the expression, hence it is the final result. 16 * Pop c and d from the stack, add, and push the result back 8 2 + Push 8 c d d Push 8 c c Pop a and b from the stack, add, and push the result back 8 + Push a b b Push a a Remarks Stack Input Symbol
  • 36.
  • 37. Converting Infix to RPN (a+b)*(c+d)  ab+cd+* Pop remaining symbols from the stack and display RPN  a b + c d + * End of input Pop till “(” is found and display – RPN  a b + c d + * )‏ Operand – display – RPN  a b + c d * ( + d Push as + has higher precedence than ( * ( + + Operand – display – RPN  a b + c * ( c Push * ( ( Push as stack is empty * * Pop till “(” is found and display – RPN  a b + )‏ Operand – display – RPN  a b ( + b Push as + has higher precedence than ( ( + + Operand – display – RPN  a ( a Push ( ( Remarks Stack Input Symbol
  • 38. a+b*c/(d+e)  a b c * d e + / + Pop till “(” is found – RPN  a b c * d e + + / )‏ Pop remaining symbols from the stack and display RPN  a b c * d e + / + End of input Operand – display – RPN  a b c * d e + / ( + e Push as + has higher precedence than ( + / ( + + Operand – display – RPN  a b c * d + / ( d Push + / ( ( Pop * and push / as * and / have the same precedence but / has higher precedence than + – RPN  a b c * + / / Operand – display – RPN  a b c + * c Push as * has higher precedence than + + * * Operand – display – RPN  a b + b Push as stack is empty + + Operand – display – RPN  a a Remarks Stack Input Symbol
  • 39.
  • 40.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.

Hinweis der Redaktion

  1. All the operations on the stack are synchronized with each other.