-
Notifications
You must be signed in to change notification settings - Fork 0
/
priority2.c
72 lines (72 loc) · 1.26 KB
/
priority2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<stdio.h>
#include<stdlib.h>
#define N NULL
typedef struct queue
{
char d;
int p;
struct queue *n;
}node;
node* gn(char data,int pri)
{
node *x=(node *)malloc(sizeof(node));
x->p=pri;
x->d=data;
return x;
}
void insert(node **h,char data,int pri)
{
node *t=*h,*x=gn(data,pri);
if(*h==N || (*h)->p > pri)
{
x->n=*h;
*h=x;
}
else
{
while(t->n!=N && t->n->p <= pri)
t=t->n;
x->n=t->n;
t->n=x;
}
}
char del_Front(node **h)
{
char z;
if(*h==N)
return '0';
else
{
node *t=*h;
z=(*h)->d;
*h=(*h)->n;
free(t);
}
return z;
}
int main()
{
char data;
int priority;
node *h=N;
printf("Enter your data (0 to terminate) and priority : \n");
while(1)
{
printf("Enter data : ");
scanf("%s",&data);
if(data=='0')
break;
printf("Enter its priority : ");
scanf("%d",&priority);
printf("\n");
insert(&h,data,priority);
}
while(1)
{
data=del_Front(&h);
if(data=='0')
break;
printf("%4c\n",data);
}
return 0;
}