ARRAY BASED STACK DATED: 30 TH AUG 2012 CLASS - XII.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Data Structure HKOI training /4/2010 So Pak Yeung.
DATA STRUCTURES ( C++ ) This PPT is Dedicated to my inner controller AMMA BHAGAVAN-Oneness Founders. Developed by,EDITED BY, S.V.G.REDDY,M.Siva Naga Prasad,
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Data Structures Queue Namiq Sultan 1. Queue A queue is an ordered collection of items into which items may be added at one end (rear) and from which items.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues.
Queues CS 3358 – Data Structures. What is a queue? It is an ordered group of homogeneous items of elements. Queues have two ends: – Elements are added.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Introduction to Stacks & Queues.
WELCOME TO Linked List, Stack & Queue By VINAY ALEXANDER PGT COMPUTER SCIENCE) KV JHAGRAKHAND.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
COP3538 – Data Structures Using OOP Chapter 4 – Stacks and Queues.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
1 Lecture 24 Abstract Data Types (ADT) –I Overview  What is an Abstract Data type?  What is Stack ADT?  Stack ADT Specifications  Array Implementation.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
Stack and Queue.
Reference: Vinu V Das, Principles of Data Structures using C and C++
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
 STACK STACK  BASIC STACK OPERATIONS BASIC STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  EVALUATING A POSTFIX EXPRESSION.
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Inheritance Examples. Example Of Multiple Inheritance class personnel { protected: char name[30]; char addr[30]; char [30]; char birth_date[30];
Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Data Structures Stack Namiq Sultan 1. Data Structure Definition: Data structures is a study of different methods of organizing the data and possible operations.
Object-Oriented Programming Simple Stack Implementation.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
Queue 09/10/081. Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called.
EC-211 DATA STRUCTURES LECTURE 9. Queue Data Structure An ordered group of homogeneous items or elements. Queues have two ends: – Elements are added at.
Data Structures & Algorithms
Introduction Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle.
CHP-4 QUEUE. 1.INTRODUCTION  A queue is a linear list in which elements can be added at one end and elements can be removed only at other end.  That.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
Definition: A stack is an ordered collection of elements in which insertions(Push) and deletions(Pop) are restricted to one end. LIFO(Last In First Out)
Stacks & Queues. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy to use.
Computer Engineering Rabie A. Ramadan Lecture 6.
STACK Data Structure
Data Structures and Algorithms IT12112 Lecture 03.
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
UNIT-1 UNIT – I Introduction to data structures: Abstract data type (ADT), Stacks and Queues circular queues and their implementation with arrays. Stack.
الطابور QUEUE (abstract data type) واحد من هياكل البيانات الخطية الشائعة الاستخدام داخل البرامج. يحتوي علي عناصر من نفس النوع. من أنواع البيانات الخطية.
Data Structure Lecture 1.  The Logical Organization of Data is called data structures  organize data  more efficient programs.  More powerful computers.
STACKS & QUEUES for CLASS XII ( C++).
What is a Queue? Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. In a queue data structure,
Data Structures Lakshmish Ramaswamy.
UNIT II Queue.
QUEUES.
Queue data structure.
Stack and Queue APURBO DATTA.
Queues Mohammad Asad Abbasi Lecture 5
Instructor: Mr.Vahidipour
סוגי נתונים מופשטים (Abstract Data Type)
ليست هاي پيوندي.
Stack and Queues Stack implementation using Array
Stack and Queues Stack implementation using Array
Example 16 Circular Queue
UNIT-I Topics to be covere d 1.Introduction to data structures.
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Abstract Data Type Abstract Data Type as a design tool
Stacks Data structure Elements added, removed from one end only
UNIT-II.
LAB#3 Stacks Nora Albabtin nora albabtin.
22C:21 Discrete Structures
Presentation transcript:

ARRAY BASED STACK DATED: 30 TH AUG 2012 CLASS - XII

#include #define MAX 6 int stack[MAX]; int top=-1; void push(int x) { if(top==MAX-1) { cout<<"\n Stack overflows \n"; return; } top=top+1; stack[top]=x; }

void pop() { if(top==-1) { cout<<"\n Stack underflows \n"; return; } cout<<"\n popped :"<<stack[top]; top=top-1; }

void show() { cout<<"\n showing....\n"; for(int i=top;i>=0;i--) cout<<stack[i]<<" "; }

void main() { void push(int); void pop(); void show(); for(int i=1;i<=5;i++) push(i); show(); pop(); show(); for(int j=6;j<=8;j++) push(j); show(); getch(); }

#include #define MAX 50 class Stack { int arr[MAX]; int top; public: Stack() { top =-1; } void push(int); void pop(); void show(); };

void Stack::push(int x) { if(top==MAX-1) { cout<<"\n stack overflows\n"; return; } arr[++top]=x; }

void Stack::pop() { if(top==-1) { cout<<"\n stack underflows\n"; return; } cout<<"\n popped:"<<arr[top]; top--; }

void Stack::show() { if(top==-1) { cout<<"\n stack underflows\n"; return; } cout<<"\n showing..\n"; for(int i=top;i>=0;i--) cout<<arr[i]<<" "; }

void main() { Stack s; for(int i=1;i<=5;i++) s.push(i); s.show(); s.pop(); s.show(); for(int j=6;j<=9;j++) s.push(j); s.show(); getch(); }

ARRAY BASED LINEAR QUEUE DATED: 30 TH AUG 2012 CLASS - XII

#include #define MAX 6 Class Queue { Int arr[MAX]; Int front, rear; Public: Queue( ) { front = rear =-1; } Void add(int); Void del(); Void show(); };

Void Queue:: add(int x) { If(rear == MAX -1) { cout<< “Queue is full “; return; } Rear++; Arr[rear]=x; If(front == -1) Front =0; }

Void Queue:: del() { If(front == -1) { cout<< “Queue is empty “; return; } Cout<<“\n value deleted :” << arr[front]; If(front ==rear) Front = rear = -1; Else Front ++; }

Void Queue:: show() { If(front == -1) { cout<< “Queue is Empty “; return; } Cout<<“\n showing…….\n”; For(int i =front ; i<=rear; i++) Cout<<arr[i]<<“ “; }

Void main() { Clrscr(); Queue q; For(int i =1; i< =6; i++) q.add(i*2); q.show(); For( int j=1; j<=3;j++) q.del(); q.show(); getch(); }

ARRAY BASED CIRCULAR QUEUE DATED: 30 TH AUG 2012 CLASS - XII

#include #define MAX 6 Class cQueue { Int arr[MAX]; Int front, rear; Public: Queue( ) { front = rear =0; } Void add(int); Void del(); Void show(); };

Void cQueue:: add(int x) { If( (front==0 && rear ==MAX -1) && (front == rear + 1) ) { cout<< “Queue is full “; return; } If(rear == -1) front = rear =0; Else if(rear == MAX -1) rear =0; Else rear++; Arr[rear]=x; }

Void cQueue:: del() { If(front == -1) { cout<< “Queue is empty “; return; } cout<<“\n value deleted :” << arr[front]; If(front == rear) Front = rear = -1; Else if(front == MAX – 1) front =0; Else Front ++; }

Void cQueue:: show() { If(front == -1) { cout<< “Queue is Empty “; return; } Cout<<“\n showing…….\n”; If(front< rear) { For(int i =front ; i<=rear; i++) Cout<<arr[i]<<“ “; } Else { for(int i=front; i<=MAX -1; i++) Cout<<arr[i]<<“ “; for( i= 0; i<=rear; i++) Cout<<arr[i]<<“ “; }

#define MAX 6 class cQueue { int arr[6]; int front, rear; public: cQueue() { front =rear =0; } void add(int); void del(); void show(); };

void cQueue::add(int x) { if( (rear+1)%MAX==front) { cout<<"\n Queue overflows"; return; } arr[rear]=x; rear = (rear+1)%MAX; }

void cQueue::del() { if(front == rear) { cout<<"\n Queue underflows"; return; } cout<<"\n deleted :"<<arr[front]; front = (front+1)%MAX; }

void cQueue::show() { if(front == rear) { cout<<"\n Queue underflows"; return; } cout<<"\n showing...\n"; for(int i=front; i!=rear; i = (i+1)%MAX) cout<<arr[i]<<“ “; }

Void main() { Clrscr(); Queue q; For(int i =1; i< =6; i++) q.add(i*2); q.show(); For( int j=1; j<=3;j++) q.del();q.add(21); q.show(); Getch(); }