Sunday, 27 November 2011

C Program of Priority Queue


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
  int queue[10],val,i,ch,pos,m,h;
  for(i=0;i<=10;i++)
     queue[i] = 0;
  do{
     printf("1.insert 2.delete 3.display 4.exit");
scanf("%d",& ch);
if(ch == 1)
 {
   printf("enter value");
scanf("%d" & val);
printf("enter position");
scanf("%d", & pos);
if(pos<9 && queue[pos] == 0)
queue[pos]=val;
else
printf("position is not valid");
 }
if(ch == 2)
 {
   h=0;
for(i=0;i<=9;i++)
{
  if(queue[i]>h)
   {
 h=queue[i];
 m=1;
}
}
queue[m] = 0;
  }
 if(ch == 3)
  {
    for(i=0;i<=9;i++)
 {
   printf("%d" queue[i]);
 }
  }
 if(ch == 4)
  {
    exit(0);
  }
 }while(1);
 getch();
 }

  



No comments:

Post a Comment