P. 1
Stack

Stack

|Views: 3|Likes:
Published by MuhammadZahirKhan
Lecture for Stack in Computer Technology
Lecture for Stack in Computer Technology

More info:

Categories:Types, Presentations
Published by: MuhammadZahirKhan on Aug 16, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PPTX, PDF, TXT or read online from Scribd
See more
See less

11/23/2014

pdf

text

original

Data Structures - CSC2077

Lecture No. 07

Stack Applications
    

Infix to postfix conversion Infix to prefix conversion Evaluation of prefix and postfix expressions Decimal to Binary Conversion Checking Balanced Symbols

Stack Applications
    

Infix to postfix conversion Infix to prefix conversion Evaluation of prefix and postfix expressions Decimal to Binary Conversion Checking Balanced Symbols

Balance Sequence

Balance Sequence
{[]}  {((()))}

Un-Balanced Sequence
{[}  ([[))

Algorithm for Checking Balance Sequence

Push on the Stack if character is Opening symbol If it is closing symbol)
If stack is empty report error  Pop symbol from the stack. Report error if it is not corresponding opening symbol (

At the end if stack is not empty report error

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) Stack .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) ( .

 5+(7*9)(9-5) 5 + ( 7 * 9 ) ( 9 5 ) Operation is Successful .

 5+)7*9)(9-5) 5 + ) 7 * 9 ) ( 9 5 ) .

 5+)7*9)(9-5) 5 + ) 7 * 9 ) ( 9 5 ) .

 5+)7*9)(9-5) 5 + ) 7 * 9 ) ( 9 5 ) .

Queue Data Structure .

Queue Data Structure    A Stack is LIFO (Last-In. First-Out) structure In contrast. First-Out ) structure A Queue is a linear structure for which items can be only inserted at one end and removed at another end . a Queue is a FIFO (First-In.

Queue Data Structure .

FALSE otherwise  IsFull()  . FALSE otherwise Return TRUE if queue is full.Queue Operations  Enqueue(X)  Place X at the Rear of the Queue Remove the Front element and return it Return front element without removing it  Dequeue()   Front()   IsEmpty()  Return TRUE if queue is empty.

Implementation of Queue   Linked List Array .

Linked List Implementation of Queue .

Linked List Implementation front 2 8 6 rear 3 front 2 8 6 rear 3 .

Linked List Implementation Dequeue() front rear front rear 2 8 6 3 2 8 6 3 .

Linked List Implementation Dequeue() front 8 6 rear 3 front rear 8 6 3 .

Linked List Implementation enqueue(5) front 8 6 rear 3 front rear 8 6 3 .

Linked List Implementation enqueue(5) front 8 6 3 rear 5 front rear 8 6 3 5 .

void Dequeue().Linked List Implementation class LinkedQueue { private: Node* Front. int GetFront(). Node* Rear. bool IsEmpty(). void PrintQueue(). void Enqueue(int). public: LinkedQueue(). }. .

Constructor of the class LinkedQueue::LinkedQueue() { Front = NULL. } . Rear = NULL.

else return false. } .IsEmpty Member Function bool LinkedQueue::IsEmpty() { if(Front == NULL) return true.

} else Rear->SetNext(newNode). } . newNode->SetData(data).Enqueue Member Function void LinkedQueue::Enqueue(int data) { Node* newNode = new Node(). newNode->SetNext(NULL). //If Queue is Empty if(IsEmpty() == true) { Front = newNode. Rear = newNode.

Front = Front->GetNext(). } . delete temp.Dequeue Member Function void LinkedQueue::Dequeue() { Node* temp = Front.

} .GetFront Member Function int LinkedQueue::GetFront() { return Front->GetData().

if(IsEmpty() == true) { cout << "The Queue is Empty!\n\n". } . return.PrintQueue Member Function void LinkedQueue::PrintQueue() { Node* temp = Front.

} } .PrintQueue Member Function else { while(temp != NULL) { cout << temp->GetData(). } cout << "NULL\n\n". temp = temp->GetNext(). cout << " --> ".

Array Implementation .

void Enqueue(int). int Rear. void PrintQueue(). void Dequeue(). bool IsFull(). public: QueueArray().PrintQueue Member Function class QueueArray { private: int Queue[QUEUE_SIZE]. }. int GetFront(). bool IsEmpty(). int Size(). . int Front.

Constructor QueueArray::QueueArray() { Front = -1. } . Rear = -1.

Size Member Function int QueueArray::Size() { return (Rear . } .Front + 1).

IsEmpty Member Function bool QueueArray::IsEmpty() { if(Front == -1) return true. else return false. } .

IsFull Member Function bool QueueArray::IsFull() { if(Rear == QUEUE_SIZE) return true. } . else return false.

Enqueue Member Function void QueueArray::Enqueue(int item) { if(IsFull() == true) { cout << "Can't Insert because the Queue is Full!\n\n". } else { Queue[++Rear] = item. } } .

} . } else Queue[Front++].Dequeue Member Function void QueueArray::Dequeue() { if(IsEmpty() == true) { cout << "Can't Delete because the Queue is Empty!\n\n".

} else { for(int i=Front. i++) { cout << Queue[i] << endl. i<=Rear.PrintQueue Member Function void QueueArray::PrintQueue() { if(IsEmpty() == true) { cout << "The Queue is Empty!\n\n". } } } .

Questions .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->