Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full

Size: px
Start display at page:

Download "Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full"

Transcription

1 Queue A Queue is defined as linear list in which insertion is taking place at one end and deletion is taking place at the other end. The end where insertion is taking place is called as rear end. The end where deletion is taking place is called as front end. The Queue is a linear data structure where element which is inserted first is deleted first, hence queue is also called as FIFO structure(first In First Out).The fig. Shown below is an sample type queue. Basically queue is nothing but an array or a vector with a maximum capacity of size. Basic operation on queue: The important operation performed on the queue is INSERTION and DELETION. The insertion operation is called inserting an element onto rear end of the queue and deletion operation is called as deleting front element of the queue.. The pointer used to perform insertion and deletion operation on a queue is REAR and FRONT respectively. The following is the example which explains how insertion and deletion opearation can be done on the queue. Insertion FRONT=0 REAR=0 Q is Empty Front=1 Front=1 REAR= REAR= Front=1 REAR=3 Front=1 REAR=4 Q is Full DELETION FRONT=1 REAR=4 FRONT=2 REAR=4 FRONT=3 REAR= FRONT=4 REAR=4 40 FRONT=0 REAR=0 Q is Empty

2 A queue can be represented as a simple one dimensional vector and also using structure. 1. Using vector definition: Int que[80] Here que is a vector of reserved with 80 location to store integer data. Out of which user can define any number of location form 0 to 80 as size of stack. The elements in above queue can be accessed as simple as vector access. 2. Using structure definition: Struct que Int st[80]; Int front; Int rear; ; Typedef struct que QUEUE; Here QUEUE represents a stack of type struct que. Member of structure can be accessed as QUEUE. item[rear] or QUEUE.item[front]. Implementation of Insertion function: INSERT() int ele; printf( Enter the element to be insert \n ); scanf( %d,&ele); if(rear >= n) printf( Queue is Over flow\n ); return; rear++; QUEUE[rear]=ele; if(front = = 0) front = 1;

3 Implementation of Deletion function: DELETE() int ele; if(front = = 0) printf( Queue is Under flow \n ); return(0); ele = QUEUE[front]; if(front = = rear) front=0; rear=0; front++; return(ele); Write a program in C to simulate or to implement a queue using a static vector or one dimensional array of size n #include <stdio.h> int LQ[80],front=0,rear=0; int n; main() int choice=0,l; printf("enter the size of the linear Q\n"); scanf("%d",&n); while(choice!=4) printf("1 INSERT \n"); printf("2 DELETE \n"); printf("3 DISPLAY \n"); printf("4 EXIT \n"); printf("enter the choice\n"); scanf("%d",&choice); switch(choice) case 1: INSERT(); printf("lq after insertion \n"); case 2: l=delete();

4 printf("deleted element is %d\n",l); printf("lq after deletion\n"); case 3: printf("content of the LQ\n"); case 4: exit(0); INSERT() int ele,t; printf("enter the element to be insert\n"); scanf("%d",&ele); if(rear == n) printf("linear Q is Full \n"); return; rear++; LQ[rear]=ele; if(front==0) front=1; DELETE() int p; if(front == 0) printf("linear Q is Empty \n"); return(0); p=lq[front]; if(front==rear) front=0; rear=0; front++; return(p); DISPLAY() int i; if(front==0) printf("linear Q is empty \n"); return;

5 for(i=front;i<=rear;i++) printf("lq[%d]=%d \n",i,lq[i]); Write a program in C to simulate or to implement a queue using a structure in C #include <stdio.h> struct q int item[10]; int front; int rear; ; typedef struct q que; que QUEUE; int n; main() int choice = 0,l; printf("enter the size of the queue\n"); scanf("%d",&n); while(choice!=4) printf("1. INSERT \n"); printf("2. DELETE \n"); printf("3. DISPLAY \n"); printf("4. Exit \n"); printf("enter the choice \n"); scanf("%d",&choice); switch(choice) case 1: INSERT(); printf("the queue after insertion \n"); case 2: l=delete(); printf("the deleted element is %d\n",l); printf("the queue after the deletion\n"); case 3: printf("the content of the queue is \n"); case 4: exit(0);

6 INSERT() int ele; printf("enter the element\n"); scanf("%d",&ele); if(queue.rear == n) printf("queue is overflow\n"); return; QUEUE.rear++; QUEUE.item[QUEUE.rear]=ele; if(queue.front == 0) QUEUE.front=1; DELETE() int ele; if(queue.front == 0) printf("queue is underflow\n"); return(0); ele=queue.item[queue.front]; if(queue.front == QUEUE.rear) QUEUE.front=0; QUEUE.rear=0; QUEUE.front++; return(ele); DISPLAY() int i; if(queue.front == 0) printf("queue is empty \n"); return; printf("front -> "); for(i=queue.front;i<=queue.rear;i++) printf("%d-> ",QUEUE.item[i]); printf("rear\n");

7 CIRCULAR QUEUE: The major disadvantage of linear queue is the wastage of memory location. The above wastage of memory location can be over come by implementing the circular queue. The following example explains functions of circular queue. Consider a circular queue of size n=5 initially circular queue is empty with front and rear value is equal to 0. The following operation explains function of the circular queue. Implementation of Circular queue Insertion function: CQINSERT() int ele; int temp; printf( Enter the element to be insert \n ); scanf( %d,&ele); temp=rear; if(rear = = n) rear=1; rear++; if(front = = rear) printf( Circular Queue is Over flow\n ); rear=temp; CQ[rear]=ele; if(front = = 0) front=1;

8 Implementation of Circular queue Delete function: CQDELETE() int ele; if(front = = 0) printf( The Circular Queue is Under flow\n ); return(0); ele=cq[front]; if(front = = n) front = 1; if(front = = rear) front = 0; rear = 0; front++; return(ele); Write a program in C to simulate or to implement a circular queue using a static vector or one dimensional array of size n #include <stdio.h> int CQ[80],front=0,rear=0; int n; main() int choice=0,l; printf("enter the size of the circular Q\n"); scanf("%d",&n); while(choice!=4) printf("1 INSERT \n"); printf("2 DELETE \n"); printf("3 DISPLAY \n"); printf("4 EXIT \n");

9 printf("enter the choice\n"); scanf("%d",&choice); switch(choice) case 1: INSERT(); printf("cq after insertion \n"); case 2: l=delete(); printf("deleted element is %d\n",l); printf("cq after deletion\n"); case 3: printf("content of the CQ\n"); case 4: exit(0); INSERT() int ele,t; printf("enter the element to be insert\n"); scanf("%d",&ele); t=rear; if(rear == n) rear=1; rear++ if(rear!=front) CQ[rear]=ele; printf("cq is over flow\n"); rear=t; if(front==0) front=1; DELETE() int p; if(front == 0) printf("cq is underflow\n"); return(0); p=cq[front]; if(front==n) front=1; if(front==rear) front=0; rear=0;

10 front++; return(p); DISPLAY() int t; t=front; while(rear!=front) printf("cq[%d]=%d ",front,cq[front]); if(front==n) front=1; front++; printf("cq[%d]=%d ",front,cq[front]); printf("\n"); front=t;

11 PRIORITY QUEUE: An ordinary queue is works on the principle FIFO principle. In a priority queue insertion depends on the element priority. Elements are deleted either in increasing or decreasing order of priority rather than in the order in which they have arrived in the queue. A priority queue is a collection of elements each one having an assigned priority. Insertion and deletion are two basic operations to be done on this queue. The deletion operation is different from ordinary queue. The deleletion operation is classified in two types 1. Ascending priority queue (Min Priority Queue) (Elements with a minimum priority is to be deleted first) 2. Descending priority queue(max Priority Queue) ( Elements with a maximum priority is to be deleted first) Implementation of Priority queue Insertion function: QINSERT(Q,p,x) queue Q[]; int p,x; if(q[p].rear == 4) printf("queue %d is overflow\n",p); return; Q[p].rear++; Q[p].items[Q[p].rear] = x; if(q[p].front == 0) Q[p].front=1; return(q); Implementation of Priority queue Deletion function: QDELETE(Q) queue Q[]; int temp = 0; int empty, p,l; for(p=1;p<=n;p++) if(q[p].front == 0) printf("the Q[%d] is empty\n",p); l=0;

12 temp=q[p].items[q[p].front]; l=1; if(q[p].front == Q[p].rear) Q[p].front=0; Q[p].rear=0; Q[p].front++; if(l==1) printf("element %d is deleted from %d queue\n",temp,p); Write a program in C to simulate or to implement a Priority queue using a structure in C #include <stdio.h> #define n 3 struct que int items[5]; int front; int rear; ; typedef struct que queue; main() queue q[n]; int ele,choice=0; int l,i; int pri; clrscr(); for(i=1;i<=n;i++) q[i].front=0; q[i].rear=0; while(choice!=4) printf("1. insert \n"); printf("2. delete \n"); printf("3. display \n"); printf("4. exit \n"); printf("enter the choice \n"); scanf("%d",&choice); switch(choice) case 1: printf("enter the priority and element \n");

13 scanf("%d %d",&pri,&ele); QINSERT(q,pri,ele); printf("the content of the priority Q after insertion\n"); QDISPLAY(q); case 2: QDELETE(q); printf("the content of priority Q after deletion is \n"); QDISPLAY(q); case 3: printf("the content of the Priority Q is \n"); QDISPLAY(q); case 4: exit(0); QINSERT(Q,p,x) queue Q[]; int p,x; if(q[p].rear == 4) printf("queue %d is overflow\n",p); return; Q[p].rear++; Q[p].items[Q[p].rear] = x; if(q[p].front == 0) Q[p].front=1; return(q); QDELETE(Q) queue Q[]; int temp = 0; int empty, p,l; for(p=1;p<=n;p++) if(q[p].front == 0) printf("the Q[%d] is empty\n",p); l=0; temp=q[p].items[q[p].front]; l=1; if(q[p].front == Q[p].rear) Q[p].front=0; Q[p].rear=0; Q[p].front++; if(l==1)

14 printf("element %d is deleted from %d queue\n",temp,p); QDISPLAY(Q) queue Q[]; int i,p; for(p=1;p<=n;p++) printf("queue : %d\n",p); if(q[p].front == 0) printf("empty\n"); for(i=q[p].front;i<=q[p].rear;i++) printf("%d ",Q[p].items[i]); printf("\n"); printf("\n \n");

Queue: Queue Representation: Basic Operations:

Queue: Queue Representation: Basic Operations: Queue: Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3 Linear and Non-Linear Data Structures Linear data structure: Linear data structures are those data structure in which data items are arranged in a linear sequence by physically or logically or both the

More information

DS Lab Manual -17CS33

DS Lab Manual -17CS33 Chethan Raj C Assistant Professor Dept. of CSE 6. Design, Develop and Implement a menu driven Program in C for the following operations on Circular QUEUE of Characters (Array Implementation of Queue with

More information

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type

More information

UNIT-2 Stack & Queue

UNIT-2 Stack & Queue UNIT-2 Stack & Queue 59 13. Stack A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

Data Structures II Lesson 1 (Circular Queue)

Data Structures II Lesson 1 (Circular Queue) Data Structures II Lesson 1 (Circular Queue) Introduction The circular queue: is a queue where the last location in it is linked to the first location As shown in figure 1, location (5) which is the last

More information

MODULE V: POINTERS & PREPROCESSORS

MODULE V: POINTERS & PREPROCESSORS MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which

More information

Vivekananda College of Engineering & Technology. Data Structures and Applications

Vivekananda College of Engineering & Technology. Data Structures and Applications Vivekananda College of Engineering & Technology [Sponsored by Vivekananda Vidyavardhaka Sangha, Puttur ] Affiliated to Visvesvaraya Technological University Approved by AICTE New Delhi & Govt of Karnataka

More information

Government Girls Polytechnic, Bilaspur

Government Girls Polytechnic, Bilaspur Government Girls Polytechnic, Bilaspur Name of the Lab: Programming Lab Practical: Data Structure Lab Class: 4 th Semester (Computer Science & Engineering) Teachers Assessment: 30 End Semester Examination:70

More information

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees Instructor: Krithika Venkataramani Semester 2, 2011-2012 1 Introduction to Linked Lists Each bead connected to the next through a

More information

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. Table of Contents 1. Simple Queue Implementation with arrays...3 2. Circular queue with global container

More information

DS Assignment II. Full Sized Image

DS Assignment II. Full Sized Image DS Assignment II 1. A) For the Towers of Hanoi problem, show the call tree during the recursive call Towers(3, A, C, B). In the tree, label the root node as Towers (3, A, C, B) while marking all the intermediate

More information

Class / Sem: I CSE / II Semester Subject Code: CS 6202 Subject: Programming and Data Structures I Prepared by T. Vithya Unit IV - LINEAR DATA STRUCTURES STACKS AND QUEUES Stack ADT Evaluating arithmetic

More information

UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. 1 Table of Contents 1. Array Implementation of Linked List...3 2. Queue using Array Implementation

More information

The Queues. Front. Rear. Front. Rear. Rear = 0 Front = 0. Fig Queue is empty. Fig push(10) Rear = 1 Front = 0. Fig. 4.3.

The Queues. Front. Rear. Front. Rear. Rear = 0 Front = 0. Fig Queue is empty. Fig push(10) Rear = 1 Front = 0. Fig. 4.3. 4 The Queues A queue is logically a first in first out (FIFO or first come first serve) linear data structure. The concept of queue can be understood by our real life problems. For example a customer come

More information

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List in Data Structure By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List Like arrays, Linked List is a linear data

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 17 EXAMINATION Subject Name: Data Structure Using C Model Answer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as

More information

Circular Queue can be created in three ways they are: Using single linked list Using double linked list Using arrays

Circular Queue can be created in three ways they are: Using single linked list Using double linked list Using arrays Circular Queue: Implementation and Applications In linear queue, when we delete any element, only front increment by one but position is not used later. So, when we perform more add and delete operations,

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given

More information

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table Contents #06 More Structures -07 FUNDAMENTAL PROGRAMMING I Stack Queue Hash table DEPARTMENT OF COMPUTER ENGINEERING, PSU v. Queue vs. Stack Stack Operations IN IN OUT Push: add an item to the top Pop:

More information

Guide for The C Programming Language Chapter 5

Guide for The C Programming Language Chapter 5 1. Differentiate between primitive data type and non-primitive data type. Primitive data types are the basic data types. These data types are used to represent single values. For example: Character, Integer,

More information

Data Structures. Lecture 5 : The Queues

Data Structures. Lecture 5 : The Queues 0 Data Structures Lecture 5 : Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University http://bu.edu.eg/staff/esamhalim14 2 A queue is logically a first in first out (FIFO

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon Data Structures &Al Algorithms Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in

More information

Data Structures. Lecture 4 : The Queues. Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University

Data Structures. Lecture 4 : The Queues. Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University 0 Data Structures Lecture 4 : Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University 2 A queue is logically a first in first out (FIFO or first come first serve) linear

More information

Solution for Data Structure

Solution for Data Structure Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT

More information

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields:

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields: Assignment 6 Q1. Create a database of students using structures, where in each entry of the database will have the following fields: 1. a name, which is a string with at most 128 characters 2. their marks

More information

STACKS 3.1 INTRODUCTION 3.2 DEFINITION

STACKS 3.1 INTRODUCTION 3.2 DEFINITION STACKS 3 3.1 INTRODUCTION A stack is a linear data structure. It is very useful in many applications of computer science. It is a list in which all insertions and deletions are made at one end, called

More information

CSCI 2132 Software Development. Lecture 20: Program Organization

CSCI 2132 Software Development. Lecture 20: Program Organization CSCI 232 Software Development Lecture 20: Program Organization Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 22-Oct-208 (20) CSCI 232 Previous Lecture Generating permutations

More information

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 100 Q.1 (a) Attempt any SIX of the following : [12] Q.1 (a) (i) Define time complexity

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code: Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA INTERNAL ASSESSMENT TEST 2 (Scheme and Solution) Data Structures Using C (16MCA11) 1) A.

More information

Methodology and Program. By Abhishek Navlakhi Semester 3: Data Structures

Methodology and Program. By Abhishek Navlakhi Semester 3: Data Structures Linked List Methodology and Program By Abhishek Navlakhi Semester 3: Data Structures This document is for private circulation for the students of Navlakhi. More educational content can be found on www.navlakhi.com

More information

Unit-2. Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks.

Unit-2. Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks. Unit-2 Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks. Queues: Introduction, Definition- Representations of Queues- Various Queue Structures- Applications

More information

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array? 1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The

More information

DEV BHOOMI INSTITUTE OF TECHNOLOGY

DEV BHOOMI INSTITUTE OF TECHNOLOGY DEV BHOOMI INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering Year: 2nd Semester: 3rd Data Structures- PCS-303 LAB MANUAL Prepared By: HOD(CSE) DEV BHOOMI

More information

Queues. Manolis Koubarakis. Data Structures and Programming Techniques

Queues. Manolis Koubarakis. Data Structures and Programming Techniques Queues Manolis Koubarakis 1 The ADT Queue A queue Q of items of type T is a sequence of items of type T on which the following operations are defined: Initialize the queue to the empty queue. Determine

More information

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

More information

Abstract Data Type: Stack

Abstract Data Type: Stack Abstract Data Type: Stack 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

More information

Structured programming

Structured programming Exercises 6 Version 1.0, 25 October, 2016 Table of Contents 1. Arrays []................................................................... 1 1.1. Declaring arrays.........................................................

More information

Model Solution for QP CODE : ( 3 Hours )

Model Solution for QP CODE : ( 3 Hours ) Model Solution for QP CODE : 24788 ( 3 Hours ) All answers are for reference only. Any alternate answer that solves the problem should be considered eqully valid. 1. (a) Define data structure? Give its

More information

PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities INTERNAL ASSESSMENT TEST-3 Date : 12-05-2016 Marks: 40 Subject & Code : Programming in C and data structures (15PCD23) Sec : F,G,H,I,J,K Name of faculty :Dr J Surya Prasad/Mr.Sreenath M V/Ms.Monika/ Time

More information

a) State the need of data structure. Write the operations performed using data structures.

a) State the need of data structure. Write the operations performed using data structures. Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

Two abstract data types. performed on them) Stacks Last In First Out (LIFO) Queues First In First Out (FIFO)

Two abstract data types. performed on them) Stacks Last In First Out (LIFO) Queues First In First Out (FIFO) Two abstract data types o Can be implemented using arrays or linked lists o Restricted lists (only a small number of operations are performed on them) Stacks Last In First Out (LIFO) Queues First In First

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

Procedural Programming

Procedural Programming Exercise 6 (SS 2016) 04.07.2015 What will I learn in the 6. exercise Math functions Dynamic data structures (linked Lists) Exercise(s) 1 Home exercise 4 (3 points) Write a program which is able to handle

More information

MC9217 / Programming and Data Structures Lab MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C

MC9217 / Programming and Data Structures Lab MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C 0 0 3 2 1.Create a Stack and do the following operations using arrays and linked lists (i)push (ii) Pop (iii) Peep 2.Create a Queue and do the following

More information

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables.

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables. When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called

More information

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines

More information

1 P age DS & OOPS / UNIT II

1 P age DS & OOPS / UNIT II UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular

More information

Scheme of valuations-test 3 PART 1

Scheme of valuations-test 3 PART 1 Scheme of valuations-test 3 PART 1 1 a What is string? Explain with example how to pass string to a function. Ans A string constant is a one-dimensional array of characters terminated by a null ( \0 )

More information

Fundamentals of Programming. Lecture 14 Hamed Rasifard

Fundamentals of Programming. Lecture 14 Hamed Rasifard Fundamentals of Programming Lecture 14 Hamed Rasifard 1 Outline Two-Dimensional Array Passing Two-Dimensional Arrays to a Function Arrays of Strings Multidimensional Arrays Pointers 2 Two-Dimensional Array

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) The queue ADT A queue is like a "natural" queue of elements. It is an ordered list in which all insertions occur at one end called

More information

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Midterm Examination October 28, 2008 12:20 p.m. 1:50 p.m. Examiners: Jason Anderson, Tom Fairgrieve, Baochun

More information

AIM:- To write a C program to create a singly linked list implementation.

AIM:- To write a C program to create a singly linked list implementation. SINGLY LINKED LIST AIM:- To write a C program to create a singly linked list implementation. ALGORITHM:- 1. Start the program. 2. Get the choice from the user. 3. If the choice is to add records, get the

More information

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack 1 12 C Data Structures 12.5 Stacks 2 Stack New nodes can be added and removed only at the top Similar to a pile of dishes Last-in, first-out (LIFO) Bottom of stack indicated by a link member to NULL Constrained

More information

Introduction to Data Structure

Introduction to Data Structure Introduction to Data Structure Introduction to Data Structure Computer is an electronic machine which is used for data processing and manipulation. When programmer collects such type of data for processing,

More information

Chapter 14. Dynamic Data Structures. Instructor: Öğr. Gör. Okan Vardarlı. Copyright 2004 Pearson Addison-Wesley. All rights reserved.

Chapter 14. Dynamic Data Structures. Instructor: Öğr. Gör. Okan Vardarlı. Copyright 2004 Pearson Addison-Wesley. All rights reserved. Chapter 14 Dynamic Data Structures Instructor: Öğr. Gör. Okan Vardarlı Copyright 2004 Pearson Addison-Wesley. All rights reserved. 12-1 Dynamic Data Structure Usually, so far, the arrays and strings we

More information

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE 1. Write a C program to perform addition, subtraction, multiplication and division of two numbers. # include # include int a, b,sum,

More information

S.Y. B.Sc. (IT) : Sem. III. Data Structures

S.Y. B.Sc. (IT) : Sem. III. Data Structures S.Y. B.Sc. (IT) : Sem. III Data Structures Time : ½ Hrs.] Prelim Question Paper Solution [Marks : 7 Q. Attempt the following (any THREE) [] Q.(a) What is algorithm and explain by on Notation? [] (A) The

More information

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear S.E. Sem. III [CMPN] Data Structures Time : 3 Hrs.] Prelim Paper Solution [Marks : 80 Q.1(a) Explain different types of data structures with examples. [5] Ans.: Types of Data Structure : Data Structures

More information

Queue. Data Structure

Queue.   Data Structure Queue Data Structure Introduction It is linear data structure It is collection of items List Queue means line of items waiting for their turn Queue has two ends Elements are added at one end. Elements

More information

Lab 10: Disk Scheduling Algorithms

Lab 10: Disk Scheduling Algorithms 1. Objective Lab 10: Disk Scheduling Algorithms Understand Disk Scheduling Algorithm and read its code for SSTF, SCAN, CSCAN in C, 2. Syllabus try to write other kinds of disk scheduling algorithms such

More information

int marks[10]; // fixed size and fixed address No change in Memory address.

int marks[10]; // fixed size and fixed address No change in Memory address. Dynamic Memory Allocation : Used When we want to allocate memory during run time. int marks[10]; // fixed size and fixed address No change in Memory address. // fixed size. ( no change in size possible

More information

DC54 DATA STRUCTURES DEC 2014

DC54 DATA STRUCTURES DEC 2014 Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y-1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as

More information

Frequently asked Data Structures Interview Questions

Frequently asked Data Structures Interview Questions Frequently asked Data Structures Interview Questions Queues Data Structure Interview Questions How is queue different from a stack? The difference between stacks and queues is in removing. In a stack we

More information

School of Electrical Engineering & Computer Science Oregon State University. CS Recitation 3 Spring 2012

School of Electrical Engineering & Computer Science Oregon State University. CS Recitation 3 Spring 2012 School of Electrical Engineering & Computer Science Oregon State University CS 261 - Recitation 3 Spring 2012 Bitwise Operators AND (&), OR ( ), XOR(^), Complement (~) In all our examples sizeof(int) =

More information

struct node{ int info; struct node *left, *right; }; typedef struct node nodeptr; A Linear Doubly Linked List

struct node{ int info; struct node *left, *right; }; typedef struct node nodeptr; A Linear Doubly Linked List 1 EEE 212 Algorithms & Data Structures Spring 05/06 Lecture Notes # 13 Outline Doubly Linked Lists Linear & Circular Doubly Linked Lists Primitive Functions in Doubly Linked Lists Application of the Doubly

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays 1 What are Arrays? Arrays are our first example of structured data. Think of a book with pages numbered 1,2,...,400.

More information

/****************************************** Application: Linked List Example Compiled on: Borland Turbo C++ 3.0

/****************************************** Application: Linked List Example Compiled on: Borland Turbo C++ 3.0 /****************************************** Application: Linked List Example Compiled on: Borland Turbo C++ 3.0 ******************************************/ #include #include /* Structure

More information

'C' Programming Language

'C' Programming Language F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax

More information

(Section : Computer Science)

(Section : Computer Science) (Section : Computer Science) 26. What will happen if we compile and execute the following program? static int count = 20; int main(void) { int i = 0; static int count = 6; while (i < count) { i++; count--;

More information

Higher National Diploma in Information Technology. First Year Second Semester Examination IT 2003-Data Structure and Algorithm.

Higher National Diploma in Information Technology. First Year Second Semester Examination IT 2003-Data Structure and Algorithm. Higher National Diploma in Information Technology First Year Second Semester Examination-2013 IT 2003-Data Structure and Algorithm Answer Guide (01) I)What is Data structure A data structure is an arrangement

More information

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size] (November 10, 2009 2.1 ) Arrays An array is a collection of several elements of the same type. An array variable is declared as type array name[size] I The elements are numbered as 0, 1, 2... size-1 I

More information

[ DATA STRUCTURES] to Data Structures

[ DATA STRUCTURES] to Data Structures [ DATA STRUCTURES] Chapter - 01 : Introduction to Data Structures INTRODUCTION TO DATA STRUCTURES A Data type refers to a named group of data which share similar properties or characteristics and which

More information

Data Structures and Applications (17CS33)

Data Structures and Applications (17CS33) 3.7 Reversing a Singly Linked List #include #include struct node int data; struct node *next; ; void insert_list(int); void display(); void revers(); struct node *head,*newnode,*tail,*temp,*temp1,*temp2;

More information

TPCT s College of Engineering, Osmanabad. Laboratory Manual DATA STRUCTURE USING C. For. Second Year Students. Manual Prepared by. Mr. T.K.

TPCT s College of Engineering, Osmanabad. Laboratory Manual DATA STRUCTURE USING C. For. Second Year Students. Manual Prepared by. Mr. T.K. TPCT s College of Engineering, Osmanabad Laboratory Manual DATA STRUCTURE USING C For Second Year Students Manual Prepared by Mr. T.K.Takbhate Author COE, Osmanabad TPCT s College of Engineering Solapur

More information

Branching is deciding what actions to take and Looping is deciding how many times to take a certain action.

Branching is deciding what actions to take and Looping is deciding how many times to take a certain action. 3.0 Control Statements in C Statements The statements of a C program control the flow of program execution. A statement is a command given to the computer that instructs the computer to take a specific

More information

What is recursion. WAP to find sum of n natural numbers using recursion (5)

What is recursion. WAP to find sum of n natural numbers using recursion (5) DEC 2014 Q1 a What is recursion. WAP to find sum of n natural numbers using recursion (5) Recursion is a phenomenon in which a function calls itself. A function which calls itself is called recursive function.

More information

DC54 DATA STRUCTURES JUNE 2013

DC54 DATA STRUCTURES JUNE 2013 Q 2 (a) Define storage class and its functions. Explain in detail scope, storage allocation and purpose of each storage class. 'Storage' refers to the scope of a variable and memory allocated by compiler

More information

Sorting & Searching. Hours: 10. Marks: 16

Sorting & Searching. Hours: 10. Marks: 16 Sorting & Searching CONTENTS 2.1 Sorting Techniques 1. Introduction 2. Selection sort 3. Insertion sort 4. Bubble sort 5. Merge sort 6. Radix sort ( Only algorithm ) 7. Shell sort ( Only algorithm ) 8.

More information

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

!#$% &'($) *+!$ 0!' 0+'&$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-!.&/+*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./ 0!'" 0+'&"$ &0-2$ 10 +3&2),&/3+, #include int main() int i, sum, value; sum = 0; printf("enter ten numbers:\n"); for( i = 0; i < 10; i++ ) scanf("%d", &value); sum = sum + value; printf("their

More information

Computer Programming for Engineering Applica4ons. Intro to Programming 10/17/13 ECE 175. The Stack Data Structure. Examples from Real Life

Computer Programming for Engineering Applica4ons. Intro to Programming 10/17/13 ECE 175. The Stack Data Structure. Examples from Real Life Computer Programming for Engineering Applica4ons ECE 175 Intro to Programming The Stack Data Structure Stack: An alloca4on of memory to store data (usually temporary data) Data are inserted, and deleted

More information

Ashish Gupta, Data JUET, Guna

Ashish Gupta, Data JUET, Guna Introduction In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station etc. The person who come first, he/she

More information

Stack & Queue on Self-Referencing Structures

Stack & Queue on Self-Referencing Structures C Programming 1 Stack & Queue on Self-Referencing Structures C Programming 2 Representation of Stack struct stack { int data ; struct stack *next ; ; typedef struct stacknode node, *stack ; C Programming

More information

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities SOLUTION OF CONTINUOUS INTERNAL EVALUATION TEST -1 Date : 27-02 2018 Marks:60 Subject & Code : Programming in C and Data Structures- 17PCD23 Name of faculty : Dr. J Surya Prasad/Mr. Naushad Basha Saudagar

More information

Implementation of Singly Linked List. To write a program to implement the concept of singly linked list.

Implementation of Singly Linked List. To write a program to implement the concept of singly linked list. Ex. No: Date: Implementation of Singly Linked List. AIM: To write a program to implement the concept of singly linked list. ALGORITHM: 1. Start 2. Creation: Get the number of elements, and create the nodes

More information

Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet

Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet 517 102 Department of Computer Science and Engineering I B. Tech C Programming Language Lab Title: Stack SVEC/IT/EXPT-CP-21 PROBLEM

More information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked List. April 2, 2007 Programming and Data Structure 1 Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element

More information

File: /media/young/d1 (180713)/Work tive_tree_search/search_defs.h Page 1 of 1

File: /media/young/d1 (180713)/Work tive_tree_search/search_defs.h Page 1 of 1 File: /media/young/d1 (180713)/Work tive_tree_search/search_defs.h Page 1 of 1 #define N 7 #define R N the number of a tree the number of expanding choices = 2*R+1 ---------------------------------------------------------

More information

Data Structure. Chapter 3 Stacks and Queues. Department of Communication Engineering National Central University Jhongli, Taiwan.

Data Structure. Chapter 3 Stacks and Queues. Department of Communication Engineering National Central University Jhongli, Taiwan. Data Structure Chapter 3 Stacks and Queues Instructor: Angela Chih-Wei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 29 Spring Outline Stack Queue A Mazing Problem

More information

Pointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Pointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Pointers and Structure Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island 1 Pointer Variables Each variable in a C program occupies space in

More information

Programming. Lists, Stacks, Queues

Programming. Lists, Stacks, Queues Programming Lists, Stacks, Queues Summary Linked lists Create and insert elements Iterate over all elements of the list Remove elements Doubly Linked Lists Circular Linked Lists Stacks Operations and implementation

More information

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 for Statement Another iterative construct in C language is the for-statement (loop). The structure or the syntax of this statement is, for (exp 1 ; exp

More information

Keywords queue, left sub list, right sub list, output array list, output linked list, input array list, divide list, sort, combine

Keywords queue, left sub list, right sub list, output array list, output linked list, input array list, divide list, sort, combine Volume 4, Issue 12, December 2014 ISSN: 2277 128X International Journal of Advanced Research in Computer Science and Software Engineering Research Paper Available online at: www.ijarcsse.com Divide and

More information

BSc.(Hons.) Business Information Systems, BSc. (Hons.) Computer Science with Network Security, BSc.(Hons.) Software Engineering

BSc.(Hons.) Business Information Systems, BSc. (Hons.) Computer Science with Network Security, BSc.(Hons.) Software Engineering BSc.(Hons.) Business Information Systems, BSc. (Hons.) Computer Science with Network Security, BSc.(Hons.) Software Engineering Cohorts BIS/04 Full Time - BCNS/04 Full Time SE/04 Full Time Examinations

More information

.:: UNIT 4 ::. STACK AND QUEUE

.:: UNIT 4 ::. STACK AND QUEUE .:: UNIT 4 ::. STACK AND QUEUE 4.1 A stack is a data structure that supports: Push(x) Insert x to the top element in stack Pop Remove the top item from stack A stack is collection of data item arrange

More information