PPS Lab Manual
PPS Lab Manual
TECHNOLOGY
(KMIT)
(Approved by AICTE, New Delhi and Affiliated to JNTUH)
Narayanaguda, Hyderabad – 500029
(Autonomous)
S.NO TOPIC
I List of Experiments
II V/M /POs/PSOs/PEOs
To be the fountain head of latest technologies, producing highly skilled, globally competent
engineers.
● To establish Industry Institute Interaction to make students ready for the industry.
● To encourage and enable students to not merely seek jobs from the industry but also to create
new enterprises
● To induce a spirit of nationalism which will enable the student to develop, understand India’s
challenges and to encourage them to develop effective solutions.
● To support the faculty to accelerate their learning curve to deliver excellent service to
students
KESHAV MEMORIAL INSTITUTE OF TECHNOLOGY
(Approved by AICTE & Govt of T.S and Affiliated to JNTUH)
To be among the region's premier teaching and research Computer Science and Engineering
departments producing globally competent and socially responsible graduates in the most
conducive academic environment.
● To provide faculty with state of the art facilities for continuous professional development and
research, both in foundational aspects and of relevance to emerging computing trends.
● To impart skills that transform students to develop technical solutions for societal needs and
inculcate entrepreneurial talents.
● To inculcate an ability in students to pursue the advancement of knowledge in various
specializations of Computer Science and Engineering and make them industry-ready.
● To engage in collaborative research with academia and industry and generate adequate
resources for research activities for seamless transfer of knowledge resulting in sponsored
projects and consultancy.
● To cultivate responsibility through sharing of knowledge and innovative computing solutions
that benefits the society-at-large.
● To collaborate with academia, industry and community to set high standards in academic
excellence and in fulfilling societal responsibilities.
KESHAV MEMORIAL INSTITUTE OF TECHNOLOGY
(Approved by AICTE & Govt of T.S and Affiliated to JNTUH)
3-5-1026, Narayanaguda, Hyderabad-29. Ph: 040-23261407
PSO2: Shall have expertise on the evolving technologies like Python, Machine Learning, Deep
Learning, Internet of Things (IOT), Data Science, Full stack development, Social Networks,
Cyber Security, Big Data, Mobile Apps, CRM, ERP etc.
KESHAV MEMORIAL INSTITUTE OF TECHNOLOGY
(Approved by AICTE & Govt of T.S and Affiliated to JNTUH)
3-5-1026, Narayanaguda, Hyderabad-29. Ph: 040-23261407
PEO2: Graduates will try and provide solutions to challenging problems in their profession by
applying computer engineering principles.
PEO4: Graduates will communicate effectively, work collaboratively and exhibit high levels of
professionalism and ethical responsibility.
KESHAV MEMORIAL INSTITUTE OF TECHNOLOGY
(Approved by AICTE & Govt of T.S and Affiliated to JNTUH)
3-5-1026, Narayanaguda, Hyderabad-29. Ph: 040-23261407
Course Outcomes: After learning the contents of this course the student is able to
● Choose the appropriate data structure for modeling a given problem.
● Implement operations like searching, insertion, and deletion, traversing mechanism on various
data structures.
● Students will be able to implement Linear and Non-Linear data structures.
● Implement appropriate sorting/searching technique for given problem.
CO VS PO MAPPING:
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 3 3 3 3 2 2 2
CO3 3 3 3 3 3 2
CO4 3 3 3 3 3 2
1. Write a simple program that prints the results of all the operators available in C
(including pre/ post increment, bitwise and/or/not, etc.). Read required operand
values from standard input.
#include<stdio.h>
void main( )
int a,b,min,n1,n2,n3,n4;
scanf("%d %d",&a,&b);
min=a<b?a:b;
printf("a+b -> %d a-b -> %d a*b -> %d a/b -> %d a mod b -> %d\n", a+b,a-
b,a*b,a/b,a%b);
printf("a>b -> %d a<b -> %d a>=b -> %d a<=b -> %d a==b -> %d a!=b -> %d\
n", a>b,a<b,a>=b,a<=b,a==b,a!=b);
printf("a&b -> %d a|b -> %d a^b -> %d a<<2 -> %d b>>3 -> %d\n",a&b,a|
b,a^b,a<<2,b>>3);
n1=a++;
n2=++a;
n3=b--;
n4=--b;
Output:
a+b -> 41 a-b -> 9 a*b -> 400 a/b -> 1 a mod b -> 9
a>b -> 1 a<b -> 0 a>=b -> 1 a<=b -> 0 a==b -> 0 a!=b -> 1
a&b -> 16 a|b -> 25 a^b -> 9 a<<2 -> 100 b>>3 -> 2
#include<stdio.h>
int main()
float average;
scanf("%d %d %d",&sub1,&sub2,&sub3);
return 0;
Output:
Minimum is 1
Maximum is 5
4. Write the program for the simple, compound interest.
#include<stdio.h>
#include<math.h>
int main()
scanf("%f", &p);
scanf("%f", &t);
scanf("%f", &r);
si = (p * t * r)/100.0;
ci = p * (pow(1+r/100, t) - 1);
return(0);
Output:
void main()
float percentage;
scanf("%f", &percentage);
printf("Distinction");
else if(percentage<40 )
printf("Failed");
printf("Second Class");
{
printf("First Class");
Output:
Enter percentage: 78
Distinction
6. Write a C program to find the roots of a Quadratic equation
#include <stdio.h>
#include <math.h>
int main()
discriminant = b*b-4*a*c;
if(a==0&&b==0&&c==0)
else if(a==0){
x=(float)-c/b;
root1 = (-b+sqrt(discriminant))/(2*a);
root2 = (-b-sqrt(discriminant))/(2*a);
else if (discriminant == 0)
else
realPart = -b/(2*a);
imaginaryPart = sqrt(-discriminant)/(2*a);
return 0;
Output:
void main()
int a, b, c;
char ch;
scanf("%c", &ch);
switch(ch)
case '+': c = a + b;
break;
case '-': c = a - b;
break;
case '*': c = a * b;
case '/': c = a / b;
break;
case '%': c = a % b;
break;
break;
Output:
Quotient is 10
8. Write a program that prints a multiplication table for a given number and the
number of rows in the table. For example, for a number 5 and rows = 3, the output
should be:
5x1=5
5 x 2 = 10
5 x 3 = 15
#include <stdio.h>
int main()
{
int number, r,i=1;
printf("Enter the Number:");
scanf("%d", &number);
printf("Enter the number of rows in the table:");
scanf("%d",&r);
while (i <= r)
{
printf("%d x %d = %d\n", number, i, number * i);
i++;
}
return 0;
}
Output:
Enter the Number:18
Enter the number of rows in the table:3
18 x 1 = 18
18 x 2 = 36
18 x 3 = 54
9. Write a program that finds if a given number is a prime number
#include<stdio.h>
int main() {
int n, i, count = 0;
scanf("%d", &n);
if (n % i == 0) {
count++;
if (count ==2) {
else {
return 0;
Output:
0 1 1 2 3 5 8 13
12. Write a program that shows the binary equivalent of a given positive number
between 0 to 255.
#include <stdio.h>
int main()
long bin=0;
scanf("%d", &num);
if(num>=0)
num2=num;
while (num!=0)
rem = num%2;
num = num / 2;
else
{
Output:
2 3 5 7 11 13
14. Write a C program to calculate the following, where x is a fractional value.
1-x/2 +x^2/4-x^3/6
#include <stdio.h>
#include <math.h>
void main()
{
int counter,i;
float sum=1,x,power,fact;
}
Output:
ENTER VALUE OF x : 15
Sum of Series is : -512.750000
15. Write a C program to read in two numbers, x and n, and then compute the sum
of this geometric progression: 1+x+x^2+x^3+………….+x^n.
example: if n is 3 and x is 5, then the program computes 1+5+25+125.
#include<stdio.h>
#include<math.h>
void main(){
int x,n,sum=1,i;
printf("Enter x and n values : ");
scanf("%d %d",&x,&n);
for(i=1;i<=n;i++)
sum+=pow(x,i);
printf("\nSum of Geometric Progression is: %d",sum);
}
Output:
int main()
int i,j,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
printf("%d ",j);
printf("\n");
return 0;
Output:
Enter no of rows: 4
1
12
123
1234
17. Write a C program to construct a pyramid of numbers as follows:
*
**
***
#include<stdio.h>
int main()
{
int i,j,n;
printf("Enter no of rows: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
Output:
Enter no of rows: 4
*
**
***
****
18. Write a C program to construct a pyramid of numbers as follows:
1
23
456
#include<stdio.h>
int main()
{
int i,j,n,k=1;
printf("Enter no of rows: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++,k++)
{
printf("%d ",k);
}
printf("\n");
}
return 0;
}
Output:
Enter no of rows: 4
1
23
456
7 8 9 10
19. Write a C program to construct a pyramid of numbers as follows:
1
22
333
4444
#include<stdio.h>
int main()
{
int i,j,n;
printf("Enter no of rows: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",i);
}
printf("\n");
}
return 0;
}
Output:
Enter no of rows: 4
22
333
4444
20.Write a C program to construct a pyramid of numbers as follows:
*
**
***
**
*
#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("\n");
}
for(i=rows-1; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("\n");
}
return 0;
}
Output:
Enter number of rows: 4
**
***
****
***
**
*
21. Write a C program to find the minimum, maximum and average in an array of
integers.
#include <stdio.h>
int main()
{
int a[50],i,n,sum,min,max;
float avg;
sum=min=max=a[0];
for(i=1; i<n; i++)
{
sum+=a[i];
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
avg=(float)sum/n;
printf("Minimum in an array of given integers : %d",min);
printf("\nMaximum in an array of given integers : %d",max);
printf("\nAverage in an array of given integers : %.2f",avg);
return 0;
}
Output:
Enter size of the array : 8
}
Output:
Enter array size : 5
Enter array elements : 4 2 7 1 3
Given array elements are : 4 2 7 1 3
24. Write a program for display values reverse order from array using pointer.
#include<stdio.h>
void main()
{
int a[10],n,i,*p;
printf("Enter array size : ");
scanf("%d",&n);
p=&a[n-1];
printf("Enter array elements : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
Output:
Enter array size : 5
Enter array elements : 5 3 2 8 1
The reverse order of the given array elements : 1 8 2 3 5
25. Write a program through a pointer variable to find sum of n elements from the
array.
#include <stdio.h>
void main()
{
int i,a[20], n, sum = 0;
int *p;
p=a;
printf("Enter the size of array : ");
scanf("%d",&n);
int main()
FILE *fp;
char ss[50],ch;
int cc=0,wc=1,lc=1,i;
scanf("%[^#]s",ss);
for(i=0;ss[i]!='\0';i++)
ch=ss[i];
if(ch=='\n'||ch=='\t'||ch==' ')
wc++;
if(ch=='\n')
lc++;
cc++;
}
32. Write a C program to find the minimum, maximum and average in an array of
integers.
#include <stdio.h>
int main()
{
int a[50],i,n,sum,min,max;
float avg;
sum=min=max=a[0];
for(i=1; i<n; i++)
{
sum+=a[i];
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
avg=(float)sum/n;
printf("Minimum in an array of given integers : %d",min);
printf("\nMaximum in an array of given integers : %d",max);
printf("\nAverage in an array of given integers : %.2f",avg);
return 0;
}
Output:
Enter size of the array : 8
Transpose of Matrix:
42
35
34. Write C program that use both recursive and non-recursive functions to find the
factorial of a given integer.
#include <stdio.h>
int nonrecfactorial(int );
int recfactorial(int );
void main()
{
int n, a, b;
printf("Enter any number: ");
scanf("%d", &n);
printf("The factorial of a given number using recursion is %d \n",
recfactorial(n));
printf("The factorial of a given number using non-recursion is %d ",
nonrecfactorial(n));
}
int recfactorial(int x)
{
int f;
if(x == 0)
{
return(1);
}
else
{
f = x * recfactorial(x - 1);
return(f);
}
}
int nonrecfactorial(int x)
{
int i, f = 1;
for(i = 1;i <= x; i++)
{
f = f * i;
}
return(f);
}
Output:
Enter any number: 5
The factorial of a given number using recursion is 120
The factorial of a given number using non-recursion is 120
35. Write C program that use both recursive and non-recursive functions to find
the GCD (greatest common divisor) of two given integers.
#include <stdio.h>
int recgcd(int , int );
int nonrecgcd(int , int );
void main()
{
int a, b;
}
int recgcd(int x, int y)
{
if(y == 0)
{
return(x);
}
else
{
return(recgcd(y, x % y));
}
}
int nonrecgcd(int x, int y)
{
int z;
while(x % y != 0)
{
z = x % y;
x = y;
y = z;
}
return(y);
}
Output:
Enter two numbers a, b: 8 12
The gcd of two numbers using recursion is 4
The gcd of two numbers using nonrecursion is 4
36. Write C programs that use both recursive and non-recursive functions to find
x^n
#include <stdio.h>
int recxpown(int , int );
int nonrecxpown(int , int );
void main()
{
int x, n;
void main()
FILE *fp;
char ch;
fp=fopen("44.c","r");
if(fp==NULL)
exit(0);
while((ch=fgetc(fp))!=EOF)
putchar(ch);
fclose(fp);
}
39. Write a C program which copies one file to another, replacing all lowercase
characters with their uppercase equivalents.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE *file1,*file2;
int i=0;
char c;
char str1[1000];
file1=fopen("file2.c","r");
file2=fopen("ex2.txt","w");
c=fgetc(file1);
while(c!=EOF)
{
str1[i]=toupper(c);
i++;
c=fgetc(file1);
}
fputs(str1,file2);
fclose(file1);
fclose(file2);
return 0;
}
40. Write a C program to count the number of times a character occurs in a text
file.
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main()
FILE *fp;
char fname[50],str[5]=".txt",c,ch;
int count=0;
scanf("%c",&ch);
scanf("%s",fname);
strcat(fname,".txt");
fp=fopen(fname,"r");
while((c=fgetc(fp))!=EOF)
if(c==ch)
count++;
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main()
FILE *fp;
char fname[50],str[5]=".txt",ch;
int cc=0,wc=1,lc=1;
scanf("%s",fname);
strcat(fname,".txt");
fp=fopen(fname,"r");
while((ch=fgetc(fp))!=EOF)
if(ch=='\n'||ch=='\t'||ch==' ')
wc++;
if(ch=='\n')
lc++;
cc++;
}
printf("\nNumber of characters is %d",cc);
}
44.Write a C program to store students' information (id, name, address, marks) into
a file and print the information from the file.
#include<stdio.h>
struct student
{
int id;
char name[20];
char address[20];
float marks;
};
void main()
{
FILE *fp;
char ch;
struct student s;
clrscr();
fp=fopen("stud.dat","wb+");
if(fp==NULL)
{
printf("Unable to create the file");
exit(0);
}
do
{
printf("Enter id,name,address,marks\n");
scanf("%d %s %s %f",&s.id,s.name,s.address,&s.marks);
fwrite((struct student*)&s,sizeof(s),1,fp);
printf("Enter y to continue");
scanf(" %c",&ch);
}while(ch!='y');
rewind(fp);
while(fwrite((struct student*)&s,sizeof(s),1,fp))
{
printf("%d %s %s %f\n",s.id,s.name,s.address,s.marks);
}
getch();
}
45. Write a C program that uses a non recursive function to search for a Key value
in a given list of integers using linear search method.
#include<stdio.h>
void linearsearch(int[],int,int);
void main()
{
int i, a[20], n, key;
}
Output:
Enter the size of an array : 5
Enter the array elements: 3 4 5 6 8
Enter the key element: 6
The key elements 6 is found at location 4.
46. Write a C program that uses a non recursive function to search for a Key value
in a given sorted list of integers using binary search method.
#include<stdio.h>
void binarysearch(int [],int,int);
void main()
{
int a[20], i, n, key;
printf("Enter no of elements: ");
scanf("%d",&n);
printf("Enter the array elements in ascending order: ");
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("Enter the key element: ");
scanf("%d", &key);
binarysearch(a,n,key);
}
void binarysearch(int a[],int n,int key)
{
int i,low, high, mid;
low = 0;
high = n - 1;
while(high >= low)
{
mid = (low + high) / 2;
if(key == a[mid])
break;
else if(key > a[mid])
low = mid + 1;
else
high = mid - 1;
}
if(key == a[mid])
printf("The key element %d is found at location %d.", key,mid + 1);
else
printf("The key element %d is not found.",key);
}
Output:
Enter no of elements: 5
Enter the array elements in ascending order: 4 6 8 20 24
Enter the key element: 24
The key element 24 is found at location 5.
47. Write a C program that implements the Bubble sort method to sort a given list
of integers in ascending order.
#include <stdio.h>
int main()
{
int array[100], n, c, d, temp;
for(i=l,j=0;i<=u;i++,j++)
{
a[i]=temp[j];
}
}
void mergesort(int a[],int l,int u)
{
int mid;
if(l<u)
{
mid=(l+u)/2;
mergesort(a,l,mid);
mergesort(a,mid+1,u);
merge(a,l,mid+1,u);
}
}
void main()
{
int a[100],i,n;
clrscr();
printf("Enter the size");
scanf("%d",&n);
printf("Enter array elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
mergesort(a,0,n-1);
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch();
}
Write a C program to implement single linked list with the following operations
a) create b) insert at a position c) delete by value d) delete by position e) reverse
f) sort g) display
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*head=NULL;
void create(int x)
{
struct node *nn,*temp=head;
nn=(struct node*)malloc(sizeof(struct node));
nn->data=x;
nn->next=NULL;
if(head==NULL)
{
head=nn;
return;
}
while(temp->next!=NULL)
temp=temp->next;
temp->next=nn;
}
void addatbeg(int x)
{
struct node *nn;
nn=(struct node*)malloc(sizeof(struct node));
nn->data=x;
nn->next=head;
head=nn;
}
void ldelete(int x)
{
struct node *temp=head,*prev;
while(temp!=NULL)
{
if(temp->data==x)
{
if(temp==head)
{
head=temp->next;
}
else
{
prev->next=temp->next;
}
free(temp);
printf("Node deleted\n");
return;
}
prev=temp;
temp=temp->next;
}
printf("Element not found\n");
}
void display()
{
struct node *temp=head;
if(head==NULL)
{
printf("List is empty\n");
return;
}
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}
void sort()
{
struct node *t1,*t2;
int x;
for(t1=head;t1->next!=NULL;t1=t1->next)
{
for(t2=t1->next;t2!=NULL;t2=t2->next)
{
if(t1->data>t2->data)
{
x=t1->data;
t1->data=t2->data;
t2->data=x;
}
}
}
}
void main()
{
int x,ch,p;
clrscr();
while(1)
{
printf("\n1.create\n");
printf("2.addatbeg\n");
printf("3.addatpos\n");
printf("4.delete\n");
printf("5.sort\n");
printf("6.display\n");
printf("7.exit\n");
printf("Enter choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Enter a value\n");
scanf("%d",&x);
create(x);
break;
case 2:printf("Enter a value\n");
scanf("%d",&x);
addatbeg(x);
break;
case 3:printf("Enter a value and position\n");
scanf("%d %d",&x,&p);
addatpos(x,p);
break;
case 4:printf("Enter a value\n");
scanf("%d",&x);
ldelete(x);
break;
case 5:sort();
break;
case 6:display();
break;
case 7:exit(0);
}
}
}
53. Write a C program to implement stack using
a) arrays b) linked lists
#define size 5
#include<stdio.h>
#include<stdlib.h>
int s[size],top=-1;
void push(int x)
{
if(top==size-1)
{
printf("Stack is full\n");
return;
}
top++;
s[top]=x;
}
int pop()
{
int x;
if(top==-1)
{
printf("Stack is empty\n");
return -1;
}
x=s[top];
top--;
return x;
}
void display()
{
int i;
if(top==-1)
{
printf("Stack is empty\n");
return;
}
for(i=top;i>=0;i--)
{
printf("%d ",s[i]);
}
printf("\n");
}
void main()
{
int ch,x;
while(1)
{
printf("\n1.push\n");
printf("2.pop\n");
printf("3.display\n");
printf("4.exit\n");
printf("Enter choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Enter a value other than -1\n");
scanf("%d",&x);
push(x);
break;
case 2:x=pop();
if(x!=-1)
printf("Popped Value is %d\n",x);
break;
case 3:display();
break;
case 4:exit(0);
}
}
}
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*top=NULL;
void push(int x)
{
struct node *nn;
nn=(struct node*)malloc(sizeof(struct node));
if(nn==NULL)
{
printf("Stack is full\n");
return;
}
nn->data=x;
nn->next=top;
top=nn;
}
int pop()
{
int x;
struct node *temp=top;
if(top==NULL)
{
printf("Stack is empty\n");
return -1;
}
x=top->data;
top=temp->next;
free(temp);
return x;
}
void display()
{
struct node *temp=top;
if(top==NULL)
{
printf("Stack is empty\n");
return;
}
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}
void main()
{
int ch,x;
while(1)
{
printf("\n1.push\n");
printf("2.pop\n");
printf("3.display\n");
printf("4.exit\n");
printf("Enter choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Enter a value other than -1\n");
scanf("%d",&x);
push(x);
break;
case 2:x=pop();
if(x!=-1)
printf("Popped Value is %d\n",x);
break;
case 3:display();
break;
case 4:exit(0);
}
}
}
54. Write a C program to implement queues using
a) arrays b) linked lists
#define size 5
#include<stdio.h>
#include<stdlib.h>
int q[size],f=-1,r=-1;
void qinsert(int x)
{
if(r==size-1)
{
printf("Queue is full\n");
return;
}
r++;
q[r]=x;
if(f==-1)
f=0;
}
int qdelete()
{
int x;
if(f==-1)
{
printf("Queue is empty\n");
return -1;
}
x=q[f];
if(f==r)
f=r=-1;
else
f++;
return x;
}
void display()
{
int i;
if(f==-1)
{
printf("Queue is empty\n");
return;
}
for(i=f;i<=r;i++)
{
printf("%d ",q[i]);
}
printf("\n");
}
void main()
{
int ch,x;
while(1)
{
printf("\n1.insert\n");
printf("2.delete\n");
printf("3.display\n");
printf("4.exit\n");
printf("Enter choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Enter a value other than -1\n");
scanf("%d",&x);
qinsert(x);
break;
case 2:x=qdelete();
if(x!=-1)
printf("Deleted Value is %d\n",x);
break;
case 3:display();
break;
case 4:exit(0);
}
}
}
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*f=NULL,*r=NULL;
void qinsert(int x)
{
struct node *nn;
nn=(struct node*)malloc(sizeof(struct node));
if(nn==NULL)
{
printf("Queue is full\n");
return;
}
nn->data=x;
nn->next=NULL;
if(f==NULL&&r==NULL)
f=r=nn;
else
{
r->next=nn;
r=nn;
}
}
int qdelete()
{
int x;
struct node *temp=f;
if(f==NULL)
{
printf("Queue is empty\n");
return -1;
}
x=f->data;
if(f==r)
f=r=NULL;
else
f=temp->next;
free(temp);
return x;
}
void display()
{
struct node *temp=f;
if(f==NULL)
{
printf("Queue is empty\n");
return;
}
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}
void main()
{
int ch,x;
while(1)
{
printf("\n1.insert\n");
printf("2.delete\n");
printf("3.display\n");
printf("4.exit\n");
printf("Enter choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Enter a value other than -1\n");
scanf("%d",&x);
qinsert(x);
break;
case 2:x=qdelete();
if(x!=-1)
printf("Deleted Value is %d\n",x);
break;
case 3:display();
break;
case 4:exit(0);
}
}
}
55. Write a C program to perform the following operations using stack
a) conversion of an infix to postfix expression
b) evaluation of postfix expression.
#define size 20
#include<stdio.h>
#include<conio.h>
char s[size];
int top=-1;
char pop()
{
return s[top--];
}
while(s[top]!='#')
{
postfix[j]=pop();
j++;
}
postfix[j]='\0';
}
void main()
{
char infix[size],postfix[size];
clrscr();
printf("Enter infix expression");
scanf("%s",infix);
convert(infix,postfix);
printf("Postfix expression is %s",postfix);
getch();
}
#define size 20
#include<stdio.h>
#include<conio.h>
char s[size];
int top=-1;
char pop()
{
return s[top--];
}
while(s[top]!='#')
{
postfix[j]=pop();
j++;
}
postfix[j]='\0';
}