Linked List Spring 2013Programming and Data Structure1.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Stacks, Queues, and Linked Lists
Linked Lists.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Data Structures (Second Part) Lecture 3 : Array, Linked List, Stack & Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering.
1 Stack and Queue. 2 Stack In Out ABCCB Data structure with Last-In First-Out (LIFO) behavior.
 A queue is a waiting line…….  It’s in daily life:-  A line of persons waiting to check out at a supermarket.  A line of persons waiting.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 18 Stacks.
1 Queues and Lists. QUEUES Very similar to stacks The only difference between them is in the order in which elements are processed. A stack uses a last-in/first-out.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 7 : September 8.
Linked Lists. Outline Why linked lists? Linked lists basics Implementation Basic primitives ­Searching ­Inserting ­Deleting.
C Programming : Elementary Data Structures 2009/04/22 Jaemin
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
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.
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Stacks, Queues, and Deques
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Reference: Vinu V Das, Principles of Data Structures using C and C++
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
Queue 1 Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
CSC2100B Tutorial 2 List and stack implementation.
Stacks And Queues Chapter 18.
Slide 1 Linked Data Structures. Slide 2 Learning Objectives  Nodes and Linked Lists  Creating, searching  Linked List Applications  Stacks, queues.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
Linked Lists EENG 212 ALGORITHMS And DATA STRUCTURES.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
Data Structures – Week #4 Queues. January 12, 2016Borahan Tümer, Ph.D.2 Outline Queues Operations on Queues Array Implementation of Queues Linked List.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
1 Queues and Lists. QUEUES Very similar to stacks The only difference between them is in the order in which elements are processed. A stack uses a last-in/first-out.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
Stacks This presentation shows – how to implement the stack – how it can be used in real applications.
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
LINKED LISTS.
 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.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
STACKS & QUEUES for CLASS XII ( C++).
Chapter 12 – Data Structures
Linked List :: Basic Concepts
Data Structure Interview Question and Answers
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Stack and Queue APURBO DATTA.
Queues Chapter 4.
Stack and Queue.
Linked List Sudeshna Sarkar.
CMSC 341 Lecture 5 Stacks, Queues
Programming and Data Structure
CSCS-200 Data Structure and Algorithms
BY PROF. IRSHAD AHMAD LONE.
Presentation transcript:

Linked List Spring 2013Programming and Data Structure1

Introduction A linked list is a data structure which can change during execution. – Successive elements are connected by pointers. – Last element points to NULL. – It can grow or shrink in size during execution of a program. – It can be made just as long as required. – It does not waste memory space. Spring 2013Programming and Data Structure2 ABC head

Keeping track of a linked list: – Must know the pointer to the first element of the list (called start, head, etc.). Linked lists provide flexibility in allowing the items to be rearranged efficiently. – Insert an element. – Delete an element. Spring 2013Programming and Data Structure3

Illustration: Insertion Spring 2013Programming and Data Structure4 AA Item to be inserted X X ABC BC

Illustration: Deletion Spring 2013Programming and Data Structure5 AB ABC C Item to be deleted

In essence... For insertion: – A record is created holding the new item. – The next pointer of the new record is set to link it to the item which is to follow it in the list. – The next pointer of the item which is to precede it must be modified to point to the new item. For deletion: – The next pointer of the item immediately preceding the one to be deleted is altered, and made to point to the item following the deleted item. Spring 2013Programming and Data Structure6

Array versus Linked Lists Arrays are suitable for: – Inserting/deleting an element at the end. – Randomly accessing any element. – Searching the list for a particular value. Linked lists are suitable for: – Inserting an element. – Deleting an element. – Applications where sequential access is required. – In situations where the number of elements cannot be predicted beforehand. Spring 2013Programming and Data Structure7

Types of Lists Depending on the way in which the links are used to maintain adjacency, several different types of linked lists are possible. – Linear singly-linked list (or simply linear list) One we have discussed so far. Spring 2013Programming and Data Structure8 ABC head

– Circular linked list The pointer from the last element in the list points back to the first element. Spring 2013Programming and Data Structure9 ABC head

– Doubly linked list Pointers exist between adjacent nodes in both directions. The list can be traversed either forward or backward. Usually two pointers are maintained to keep track of the list, head and tail. Spring 2013Programming and Data Structure10 ABC headtail

Basic Operations on a List Creating a list Traversing the list Inserting an item in the list Deleting an item from the list Concatenating two lists into one Spring 2013Programming and Data Structure11

List is an Abstract Data Type What is an abstract data type? – It is a data type defined by the user. – Typically more complex than simple data types like int, float, etc. Why abstract? – Because details of the implementation are hidden. – When you do some operation on the list, say insert an element, you just call a function. – Details of how the list is implemented or how the insert function is written is no longer required. Spring 2013Programming and Data Structure12

Conceptual Idea Spring 2013Programming and Data Structure13 List implementation and the related functions Insert Delete Traverse

Example: Working with linked list Consider the structure of a node as follows: struct stud { int roll; char name[25]; int age; struct stud *next; }; /* A user-defined data type called “node” */ typedef struct stud node; node *head; Spring 2013Programming and Data Structure14

Creating a List Spring 2013Programming and Data Structure15

How to begin? To start with, we have to create a node (the first node), and make head point to it. head = (node *) malloc(sizeof(node)); Spring 2013Programming and Data Structure16 head age name roll next

Contd. If there are n number of nodes in the initial linked list: – Allocate n records, one by one. – Read in the fields of the records. – Modify the links of the records so that the chain is formed. Spring 2013Programming and Data Structure17 ABC head

node *create_list() { int k, n; node *p, *head; printf ("\n How many elements to enter?"); scanf ("%d", &n); for (k=0; k<n; k++) { if (k == 0) { head = (node *) malloc(sizeof(node)); p = head; } else { p->next = (node *) malloc(sizeof(node)); p = p->next; } scanf ("%d %s %d", &p->roll, p->name, &p->age); } p->next = NULL; return (head); } Spring 2013Programming and Data Structure18

To be called from main() function as: node *head; ……… head = create_list(); Spring 2013Programming and Data Structure19

Traversing the List Spring 2013Programming and Data Structure20

What is to be done? Once the linked list has been constructed and head points to the first node of the list, – Follow the pointers. – Display the contents of the nodes as they are traversed. – Stop when the next pointer points to NULL. Spring 2013Programming and Data Structure21

void display (node *head) { int count = 1; node *p; p = head; while (p != NULL) { printf ("\nNode %d: %d %s %d", count, p->roll, p->name, p->age); count++; p = p->next; } printf ("\n"); } Spring 2013Programming and Data Structure22

To be called from main() function as: node *head; ……… display (head); Spring 2013Programming and Data Structure23

Inserting a Node in a List Spring 2013Programming and Data Structure24

How to do? The problem is to insert a node before a specified node. – Specified means some value is given for the node (called key). – In this example, we consider it to be roll. Convention followed: – If the value of roll is given as negative, the node will be inserted at the end of the list. Spring 2013Programming and Data Structure25

Contd. When a node is added at the beginning, – Only one next pointer needs to be modified. head is made to point to the new node. New node points to the previously first element. When a node is added at the end, – Two next pointers need to be modified. Last node now points to the new node. New node points to NULL. When a node is added in the middle, – Two next pointers need to be modified. Previous node now points to the new node. New node points to the next node. Spring 2013Programming and Data Structure26

Spring 2013Programming and Data Structure27 void insert (node **head) { int k = 0, rno; node *p, *q, *new; new = (node *) malloc(sizeof(node)); printf ("\nData to be inserted: "); scanf ("%d %s %d", &new->roll, new->name, &new->age); printf ("\nInsert before roll (-ve for end):"); scanf ("%d", &rno); p = *head; if (p->roll == rno) /* At the beginning */ { new->next = p; *head = new; }

Spring 2013Programming and Data Structure28 else { while ((p != NULL) && (p->roll != rno)) { q = p; p = p->next; } if (p == NULL) /* At the end */ { q->next = new; new->next = NULL; } else if (p->roll == rno) /* In the middle */ { q->next = new; new->next = p; } The pointers q and p always point to consecutive nodes.

To be called from main() function as: node *head; ……… insert (&head); Spring 2013Programming and Data Structure29

Deleting a node from the list Spring 2013Programming and Data Structure30

What is to be done? Here also we are required to delete a specified node. – Say, the node whose roll field is given. Here also three conditions arise: – Deleting the first node. – Deleting the last node. – Deleting an intermediate node. Spring 2013Programming and Data Structure31

Spring 2013Programming and Data Structure32 void delete (node **head) { int rno; node *p, *q; printf ("\nDelete for roll :"); scanf ("%d", &rno); p = *head; if (p->roll == rno) /* Delete the first element */ { *head = p->next; free (p); }

Spring 2013Programming and Data Structure33 else { while ((p != NULL) && (p->roll != rno)) { q = p; p = p->next; } if (p == NULL) /* Element not found */ printf ("\nNo match :: deletion failed"); else if (p->roll == rno) /* Delete any other element */ { q->next = p->next; free (p); }

Few Exercises to Try Out Write a function to: – Concatenate two given list into one big list. node *concatenate (node *head1, node *head2); – Insert an element in a linked list in sorted order. The function will be called for every element to be inserted. void insert_sorted (node **head, node *element); – Always insert elements at one end, and delete elements from the other end (first-in first-out QUEUE). void insert_q (node **head, node *element) node *delete_q (node **head) /* Return the deleted node */ Spring 2013Programming and Data Structure34

A First-in First-out (FIFO) List Spring 2013Programming and Data Structure35 Also called a QUEUE In Out ACBAB

A Last-in First-out (LIFO) List Spring 2013Programming and Data Structure36 In Out ABCCB Also called a STACK

Abstract Data Types Spring 2013Programming and Data Structure37

Example 1 :: Complex numbers struct cplx { float re; float im; } typedef struct cplx complex; complex *add (complex a, complex b); complex *sub (complex a, complex b); complex *mul (complex a, complex b); complex *div (complex a, complex b); complex *read(); void print (complex a); Spring 2013Programming and Data Structure38 Structure definition Function prototypes

Spring 2013Programming and Data Structure39 Complex Number add print mul sub read div

Example 2 :: Set manipulation struct node { int element; struct node *next; } typedef struct node set; set *union (set a, set b); set *intersect (set a, set b); set *minus (set a, set b); void insert (set a, int x); void delete (set a, int x); int size (set a); Spring 2013Programming and Data Structure40 Structure definition Function prototypes

Spring 2013Programming and Data Structure41 Set union size minus intersect delete insert

Example 3 :: Last-In-First-Out STACK Assume:: stack contains integer elements void push (stack *s, int element); /* Insert an element in the stack */ int pop (stack *s); /* Remove and return the top element */ void create (stack *s); /* Create a new stack */ int isempty (stack *s); /* Check if stack is empty */ int isfull (stack *s); /* Check if stack is full */ Spring 2013Programming and Data Structure42

Spring 2013Programming and Data Structure43 STACK push create pop isfull isempty

Contd. We shall look into two different ways of implementing stack: – Using arrays – Using linked list Spring 2013Programming and Data Structure44

Example 4 :: First-In-First-Out QUEUE Assume:: queue contains integer elements void enqueue (queue *q, int element); /* Insert an element in the queue */ int dequeue (queue *q); /* Remove an element from the queue */ queue *create(); /* Create a new queue */ int isempty (queue *q); /* Check if queue is empty */ int size (queue *q); /* Return the no. of elements in queue */ Spring 2013Programming and Data Structure45

Spring 2013Programming and Data Structure46 QUEUE enqueue create dequeue size isempty

Stack Implementations: Using Array and Linked List Spring 2013Programming and Data Structure47

STACK USING ARRAY Spring 2013Programming and Data Structure48 top PUSH

STACK USING ARRAY Spring 2013Programming and Data Structure49 top POP

Stack: Linked List Structure Spring 2013Programming and Data Structure50 top PUSH OPERATION

Stack: Linked List Structure Spring 2013Programming and Data Structure51 top POP OPERATION

Basic Idea We would: – Declare an array of fixed size (which determines the maximum size of the stack). – Keep a variable which always points to the “top” of the stack. Contains the array index of the “top” element. Spring 2013Programming and Data Structure52

Basic Idea In the array implementation, we would: – Declare an array of fixed size (which determines the maximum size of the stack). – Keep a variable which always points to the “top” of the stack. Contains the array index of the “top” element. In the linked list implementation, we would: – Maintain the stack as a linked list. – A pointer variable top points to the start of the list. – The first element of the linked list is considered as the stack top. Spring 2013Programming and Data Structure53

Declaration #define MAXSIZE 100 struct lifo { int st[MAXSIZE]; int top; }; typedef struct lifo stack; stack s; struct lifo { int value; struct lifo *next; }; typedef struct lifo stack; stack *top; Spring 2013Programming and Data Structure54 ARRAYLINKED LIST

Stack Creation void create (stack *s) { s->top = -1; /* s->top points to last element pushed in; initially -1 */ } void create (stack **top) { *top = NULL; /* top points to NULL, indicating empty stack */ } Spring 2013Programming and Data Structure55 ARRAY LINKED LIST

Pushing an element into the stack void push (stack *s, int element) { if (s->top == (MAXSIZE-1)) { printf (“\n Stack overflow”); exit(-1); } else { s->top ++; s->st[s->top] = element; } Spring 2013Programming and Data Structure56 ARRAY

void push (stack **top, int element) { stack *new; new = (stack *) malloc(sizeof(stack)); if (new == NULL) { printf (“\n Stack is full”); exit(-1); } new->value = element; new->next = *top; *top = new; } Spring 2013Programming and Data Structure57 LINKED LIST

Popping an element from the stack int pop (stack *s) { if (s->top == -1) { printf (“\n Stack underflow”); exit(-1); } else { return (s->st[s->top--]); } Spring 2013Programming and Data Structure58 ARRAY

int pop (stack **top) { int t; stack *p; if (*top == NULL) { printf (“\n Stack is empty”); exit(-1); } else { t = (*top)->value; p = *top; *top = (*top)->next; free (p); return t; } Spring 2013Programming and Data Structure59 LINKED LIST

Checking for stack empty int isempty (stack *s) { if (s->top == -1) return 1; else return (0); } int isempty (stack *top) { if (top == NULL) return (1); else return (0); } Spring 2013Programming and Data Structure60 ARRAYLINKED LIST

Checking for stack full int isfull (stack *s) { if (s->top == (MAXSIZE–1)) return 1; else return (0); } Not required for linked list implementation. In the push() function, we can check the return value of malloc(). – If -1, then memory cannot be allocated. Spring 2013Programming and Data Structure61 ARRAYLINKED LIST

Example main function :: array #include #define MAXSIZE 100 struct lifo { int st[MAXSIZE]; int top; }; typedef struct lifo stack; main() { stack A, B; create(&A); create(&B); push(&A,10); push(&A,20); push(&A,30); push(&B,100); push(&B,5); printf (“%d %d”, pop(&A), pop(&B)); push (&A, pop(&B)); if (isempty(&B)) printf (“\n B is empty”); } Spring 2013Programming and Data Structure62

Example main function :: linked list #include struct lifo { int value; struct lifo *next; }; typedef struct lifo stack; main() { stack *A, *B; create(&A); create(&B); push(&A,10); push(&A,20); push(&A,30); push(&B,100); push(&B,5); printf (“%d %d”, pop(&A), pop(&B)); push (&A, pop(&B)); if (isempty(B)) printf (“\n B is empty”); } Spring 2013Programming and Data Structure63

Queue Implementation using Linked List Spring 2013Programming and Data Structure64

Basic Idea Basic idea: – Create a linked list to which items would be added to one end and deleted from the other end. – Two pointers will be maintained: One pointing to the beginning of the list (point from where elements will be deleted). Another pointing to the end of the list (point where new elements will be inserted). Spring 2013Programming and Data Structure65 Front Rear DELETION INSERTION

QUEUE: LINKED LIST STRUCTURE Spring 2013Programming and Data Structure66 front rear ENQUEUE

QUEUE: LINKED LIST STRUCTURE Spring 2013Programming and Data Structure67 front rear DEQUEUE

QUEUE using Linked List Spring 2013Programming and Data Structure68 #include struct node{ char name[30]; struct node *next; }; typedef struct node _QNODE; typedef struct { _QNODE *queue_front, *queue_rear; } _QUEUE;

Spring 2013Programming and Data Structure69 _QNODE *enqueue (_QUEUE *q, char x[]) { _QNODE *temp; temp= (_QNODE *) malloc (sizeof(_QNODE)); if (temp==NULL){ printf(“Bad allocation \n"); return NULL; } strcpy(temp->name,x); temp->next=NULL; if(q->queue_rear==NULL) { q->queue_rear=temp; q->queue_front= q->queue_rear; } else { q->queue_rear->next=temp; q->queue_rear=temp; } return(q->queue_rear); }

Spring 2013Programming and Data Structure70 char *dequeue(_QUEUE *q,char x[]) { _QNODE *temp_pnt; if(q->queue_front==NULL){ q->queue_rear=NULL; printf("Queue is empty \n"); return(NULL); } else{ strcpy(x,q->queue_front->name); temp_pnt=q->queue_front; q->queue_front= q->queue_front->next; free(temp_pnt); if(q->queue_front==NULL) q->queue_rear=NULL; return(x); }

Spring 2013Programming and Data Structure71 void init_queue(_QUEUE *q) { q->queue_front= q->queue_rear=NULL; } int isEmpty(_QUEUE *q) { if(q==NULL) return 1; else return 0; }

Spring 2013Programming and Data Structure72 main() { int i,j; char command[5],val[30]; _QUEUE q; init_queue(&q); command[0]='\0'; printf("For entering a name use 'enter '\n"); printf("For deleting use 'delete' \n"); printf("To end the session use 'bye' \n"); while(strcmp(command,"bye")){ scanf("%s",command);

Spring 2013Programming and Data Structure73 if(!strcmp(command,"enter")) { scanf("%s",val); if((enqueue(&q,val)==NULL)) printf("No more pushing please \n"); else printf("Name entered %s \n",val); } if(!strcmp(command,"delete")) { if(!isEmpty(&q)) printf("%s \n",dequeue(&q,val)); else printf("Name deleted %s \n",val); } } /* while */ printf("End session \n"); }

Problem With Array Implementation Spring 2013Programming and Data Structure74 frontrear ENQUEUE front DEQUEUE Effective queuing storage area of array gets reduced. Use of circular array indexing 0N

Queue: Example with Array Implementation Spring 2013Programming and Data Structure75 typedef struct { char name[30]; } _ELEMENT; typedef struct { _ELEMENT q_elem[MAX_SIZE]; int rear; int front; int full,empty; } _QUEUE; #define MAX_SIZE 100

Queue Example: Contd. Spring 2013Programming and Data Structure76 void init_queue(_QUEUE *q) {q->rear= q->front= 0; q->full=0; q->empty=1; } int IsFull(_QUEUE *q) {return(q->full);} int IsEmpty(_QUEUE *q) {return(q->empty);}

Queue Example: Contd. Spring 2013Programming and Data Structure77 void AddQ(_QUEUE *q, _ELEMENT ob) { if(IsFull(q)) {printf("Queue is Full \n"); return;} q->rear=(q->rear+1)%(MAX_SIZE); q->q_elem[q->rear]=ob; if(q->front==q->rear) q->full=1; else q->full=0; q->empty=0; return; }

Queue Example: Contd. Spring 2013Programming and Data Structure78 _ELEMENT DeleteQ(_QUEUE *q) { _ELEMENT temp; temp.name[0]='\0'; if(IsEmpty(q)) {printf("Queue is EMPTY\n");return(temp);} q->front=(q->front+1)%(MAX_SIZE); temp=q->q_elem[q->front]; if(q->rear==q->front) q->empty=1; else q->empty=0; q->full=0; return(temp); }

Queue Example: Contd. Spring 2013Programming and Data Structure79 main() { int i,j; char command[5]; _ELEMENT ob; _QUEUE A; init_queue(&A); command[0]='\0'; printf("For adding a name use 'add [name]'\n"); printf("For deleting use 'delete' \n"); printf("To end the session use 'bye' \n"); #include

Queue Example: Contd. Spring 2013Programming and Data Structure80 while (strcmp(command,"bye")!=0){ scanf("%s",command); if(strcmp(command,"add")==0) { scanf("%s",ob.name); if (IsFull(&A)) printf("No more insertion please \n"); else { AddQ(&A,ob); printf("Name inserted %s \n",ob.name); }

Queue Example: Contd. Spring 2013Programming and Data Structure81 if (strcmp(command,"delete")==0) { if (IsEmpty(&A)) printf("Queue is empty \n"); else { ob=DeleteQ(&A); printf("Name deleted %s \n",ob.name); } } /* End of while */ printf("End session \n"); }