Professional Documents
Culture Documents
#include<stdio.h>
int q[20],top=-1,front=-1,rear=-1,a[20][20],vis[20],stack[20];
int delete();
void add(int item);
void bfs(int s,int n);
void dfs(int s,int n);
void push(int item);
int pop();
void main()
{
int n,i,s,ch,j;
char c,dummy;
printf("ENTER THE NUMBER VERTICES ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("ENTER 1 IF %d HAS A NODE WITH %d ELSE 0 ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("THE ADJACENCY MATRIX IS\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf(" %d",a[i][j]);
}
printf("\n");
}
do
{
for(i=1;i<=n;i++)
vis[i]=0;
printf("\nMENU");
printf("\n1.B.F.S");
printf("\n2.D.F.S");
printf("\nENTER YOUR CHOICE");
scanf("%d",&ch);
printf("ENTER THE SOURCE VERTEX :");
scanf("%d",&s);
switch(ch)
{
case 1:bfs(s,n);
break;
case 2:
dfs(s,n);
break;
}
printf("DO U WANT TO CONTINUE(Y/N) ? ");
scanf("%c",&dummy);
scanf("%c",&c);
}while((c=='y')||(c=='Y'));
}
Priority Queue
In computer science, a priority queue is an abstract data type which is like a regular queue or stack
data structure, but where additionally each element has a "priority" associated with it. In a priority
queue, an element with high priority is served before an element with low priority.
/*
1. * C Program to Implement Priority Queue to Add and Delete Elements
2. */
3. #include <stdio.h>
4. #include <stdlib.h>
5.
6. #define MAX 5
7.
8. void insert_by_priority(int);
9. void delete_by_priority(int);
13.
16.
18. {
20.
25.
26. create();
27.
29. {
32.
34. {
35. case 1:
37. scanf("%d",&n);
38. insert_by_priority(n);
39. break;
40. case 2:
42. scanf("%d",&n);
43. delete_by_priority(n);
44. break;
45. case 3:
46. display_pqueue();
47. break;
48. case 4:
49. exit(0);
50. default:
52. }
53. }
54. }
55.
58. {
60. }
61.
66. {
68. return;
69. }
71. {
72. front++;
73. rear++;
75. return;
76. }
77. else
78. check(data);
79. rear++;
80. }
81.
84. {
86.
88. {
90. {
92. {
93. pri_que[j] = pri_que[j - 1];
94. }
96. return;
97. }
98. }
100. }
101.
104. {
105. int i;
106.
108. {
110. return;
111. }
112.
114. {
116. {
118. {
120. }
121.
122. pri_que[i] = -99;
123. rear--;
124.
127. return;
128. }
129. }
131. }
132.
135. {
137. {
139. return;
140. }
141.
143. {
145. }
146.
147. front = 0;
148. }
Palindrome
for number:
#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
return 0;
}
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the
receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}