#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)
PDFScanner RS - Scan, Make PDF
PDF Scanner RS – Capture, Resize, Enhance & Create PDFs Download: https://play.google.com/store/apps/details?id=com.rssoft.pdfscan...
(2).png)
-
Server #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <...
-
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...
-
ISSUE: Build error on Asterik , when you want test webrtc feature :) checking for uuid_generate_random in -luuid... no checking for uuid...
No comments:
Post a Comment