#include<stdio.h> #include<malloc.h> void insert(); void del(); void display(); struct node { int priority; int info; struct node *next; }*start, *q, *temp, *new; typedef struct node *N; int main() { int ch; do { printf( "\n[1] INSERTION\t[2] DELETION\t[3] DISPLAY [4] EXIT\t:" ); scanf( "%d", &ch ); switch ( ch ) { case 1: insert(); break; case 2: del(); break; case 3: display(); break; case 4: break; } } while ( ch < 4 ); } void insert() { int item, itprio; new = ( N* ) malloc( sizeof( N ) ); printf( "ENTER THE ELT.TO BE INSERTED :\t" ); scanf( "%d", &item ); printf( "ENTER ITS PRIORITY :\t" ); scanf( "%d", &itprio ); new->info = item; new->priority = itprio; if ( start == NULL || itprio < start->priority ) { new->next = start; start = new; } else { q = start; while ( q->next != NULL && q->next->priority <= itprio ) q = q->next; new->next = q->next; q->next = new; } } void del() { if ( start == NULL ) { printf( "\nQUEUE UNDERFLOW\n" ); } else { new = start; printf( "\nDELETED ITEM IS %d\n", new->info ); start = start->next; free( start ); } } void display() { temp = start; if ( start == NULL ) printf( "QUEUE IS EMPTY\n" ); else { printf( "QUEUE IS:\n" ); while ( temp != NULL ) { printf( "\t%d[priority=%d]", temp->info, temp->priority ); temp = temp->next; } } }
Thursday, November 24, 2011
Basic Priority queue in C
The source code of basic priority queue is given :
Subscribe to:
Post Comments (Atom)
How to enable hotspot in TPG iPhone
By default, the hotspot does not work on the phone. It will ask you to contact the provider. This video will help you bypass the network ...
-
There is none who can replace him.At least the standard which he create in is life time in the running literature it never be replaceable.Th...
-
Server #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <...
-
Error: curl: (35) Unknown SSL protocol error Cause: For node.js https connection you are using invalid certificate. Invalid certificate...
No comments:
Post a Comment