© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

Home Lab Exercise Data Structures Lab Exercise ProgramsImplementation of Queue Using Abstract Data Type▼

Implementation of Queue Using Abstract Data Type:

Algorithm Steps:

  1. Declare an array Q of size N.
  2. Assign F and R to be the front and rear pointers of the queue and assign 0 to F and R.
  3. Get the new element Y to be inserted into the queue.
  4. If R is less than N, insert Y at the end, by incrementing R by 1. Otherwise display queue is full.
  5. If F is zero then assign F to be 1.
  6. To delete an element check whether F is greater than zero, then delete an element pointed by F, otherwise display queue is empty.
  7. If F and R is equal the set F = R = 0; otherwise F = F + 1;
  8. Display the queue Q from F to R.

C Program To Implement Queue Using Abstract Data Type:

#include #include

int i, rear, front, item, s[10]; void insert ( int item, int s[ ]); void del ( int s[ ]); void display ( int s[ ]); void main( ) { int ch; clrscr( ); front = 0; rear = -1; do { printf ( “\n\n1. Insertion \n2.Deletion \n3.Exit\n ); printf ( “\nEnter your choice: \n”); { case 1: printf(“\n \t \t "Insertion \"\n\n"); if (rear >= 9) { printf ("\n\t\t"Queue is full\"\n"); } else { printf ("Enter an element\n"); scanf("%d", &item ); insert (item, s) } display (s); break; case 2: printf ("\n\t\t\"Deletion \"\n"); if ( front > rear) { printf ("\n \t\ "Queue is empty\"\n"); } else { del(s); } display (s); break; } }while (ch!=3 ); getch( ); } void insert (int item, int s[ ] ) { rear = rear + 1; s[rear] = item; } void del ( int s[ ] ) { item = s[front]; front = front +1; printf ("\n \t \t \ "Deleted element is %d \"\n \n", item); } void display (int s[ ] ) { printf (" \n "); for ( i = front; i<= rear; i++) { printf ("\t %d", s[i]); } }

SAMPLE INPUT OUTPUT:

1.INSERTION
2.DELETION
3.EXIT

ENTER YOUR CHOICE: 1

             INSERTION

ENTER AN ELEMENT: 11

             11

1.INSERTION
2.DELETION
3.EXIT

ENTER YOUR CHOICE: 1

INSERTION

ENTER AN ELEMENT: 12

    12

1.INSERTION
2.DELETION
3.EXIT

ENTER YOUR CHOICE: 1

INSERTION

ENTER AN ELEMENT: 13
             11        12        13
         
1.INSERTION
2.DELETION
3.EXIT

ENTER YOUR CHOICE: 2

DELETION

DELETED ELEMENT IS 11

13

1.INSERTION
2.DELETION
3.EXIT

ENTER YOUR CHOICE: 2

DELETION

DELETED ELEMENT IS 12
13

1.INSERTION
2.DELETION
3.EXIT

ENTER YOUR CHOICE: 2

DELETION

QUEUE IS EMPTY


1.INSERTION
2.DELETION
3.EXIT

ENTER YOUR CHOICE: 3

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom