SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
SUBMITTED TO SUBMITTED BY
MOHIT SIR PARNEET KAUR
MCA 2nd
YEAR
ROLL NO: 201880032
DEPARTMENT OF COMPUTER SCIENCE
THAPAR INSTITUTE
OF ENGINEERING TECHNOLOGY
PATIALA
LIST OF PROGRAMS
Program of Insertion sort
Program of Selection Sort
Program of Bubble Sort
Program of Merging two arrays
Program of Multiplication of 2d
Program of Linear Search
Program of Binary Search
Program of Push and Pop operations in stack
using the application of string
Program of Quick Sort
Program of Infix to Postfix Evaluation
Program of Postfix Evaluation
Program of Tower of Hanoi
Program of Circular Queue
Program of Insertion and Deletion operation
in Queue
Program of insertion sort
#include<stdio.h>
int main()
{
int i, k, count, temp, number[100];
printf("Enter the number of the terms you want to insert: ");
scanf("%d",&count);
printf("Enter %d elements: n", count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
for(i=1;i<count;i++){
temp=number[i];
k=i-1;
while((temp<number[k])&&(k>=0)){
number[k+1]=number[k];
k=k-1;
}
number[k+1]=temp;
}
printf("Number in ascending order");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}
Program of Selection Sort
#include<stdio.h>
int main(){
int i, k, count, temp, number[40];
printf("Enter the number of terms you want to insert: ");
scanf("%d",&count);
printf("Enter %d elements:n", count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
for(i=0;i<count;i++){
for(k=i+1;k<count;k++){
if(number[i]>number[k]){
temp=number[i];
number[i]=number[k];
number[k]=temp;
}
}
}
printf("Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}
Program of Bubble Sort
#include<stdio.h>
int main(){
int count, temp, i, k, number[100];
printf("Enter the number of the terms you want to insert: ");
scanf("%d",&count);
printf("Enter %d numbers: n",count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
for(i=count-2;i>=0;i--){
for(k=0;k<=i;k++){
if(number[k]>number[k+1]){
temp=number[k];
number[k]=number[k+1];
number[k+1]=temp;
}
}
}
printf("Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}
Program of Merging two arrays
#include <stdio.h>
int main()
{
int array1[50], array2[50], array3[100], m, n, i, j, k = 0;
printf("n Enter size of array Array 1: ");
scanf("%d", &m);
printf("n Enter sorted elements of array 1: n");
for (i = 0; i < m; i++)
{
scanf("%d", &array1[i]);
}
printf("n Enter size of array 2: ");
scanf("%d", &n);
printf("n Enter sorted elements of array 2: n");
for (i = 0; i < n; i++)
{
scanf("%d", &array2[i]);
}
i = 0;
j = 0;
while (i < m && j < n)
{
if (array1[i] < array2[j])
{
array3[k] = array1[i];
i++;
}
else
{
array3[k] = array2[j];
j++;
}
k++;
}
if (i >= m)
{
while (j < n)
{
array3[k] = array2[j];
j++;
k++;
}
}
if (j >= n)
{
while (i < m)
{
array3[k] = array1[i];
i++;
k++;
}
}
printf("n After merging: n");
for (i = 0; i < m + n; i++)
{
printf("n%d", array3[i]);
}
}
Program of Multiplication of 2d
# include <stdio.h>
# include <conio.h>
int main()
{
int mata[10][10], matb[10][10], matc[10][10] ;
int i, j, k, row1, col1, row2, col2 ;
printf("Enter the order of first matrix : n") ;
scanf("%d %d", &row1, &col1) ;
printf("nEnter the order of second matrix : n") ;
scanf("%d %d", &row2, &col2) ;
if(col1 == row2)
{
printf("nEnter the elements of first matrix : nn") ;
for(i = 0 ; i < row1 ; i++)
for(j = 0 ; j < col1 ; j++)
scanf("%d", &mata[i][j]) ;
printf("nEnter the elements of second matrix : nn") ;
for(i = 0 ; i < row2 ; i++)
for(j = 0 ; j < col2 ; j++)
scanf("%d", &matb[i][j]) ;
for(i = 0 ; i < row1 ; i++)
{
for(j = 0 ; j < col2 ; j++)
{
matc[i][j] = 0 ;
for(k = 0 ; k < col1 ; k++)
matc[i][j] = matc[i][j] + mata[i][k] * matb[k][j] ;
}
}
printf("nThe resultant matrix is : nn") ;
for(i = 0 ; i < row1 ; i++)
{
for(j = 0 ; j < col2 ; j++) {
printf("%d t", matc[i][j]) ;
}
printf("n") ;
}
}
else
printf("nMatrix Multiplication is not possible ...") ;
getch() ;
}
Program of Linear Search
#include<stdio.h>
int main()
{
int a[20],i,x,n;
printf("Enter the number of element should be available in array: ");
scanf("%d",&n);
printf("Enter array elements:n");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
printf("nEnter element to search: ");
scanf("%d",&x);
for(i=0;i<n;++i)
if(a[i]==x)
break;
if(i<n)
printf("Element found at index %d",i);
else
printf("Element not found");
return 0;
}
Program of Binary Search
#include<stdio.h>
int main()
{
int arr[50],i,n,x,flag=0,first,last,mid;
printf("Enter size of array: ");
scanf("%d",&n);
printf("nEnter array element(ascending order)n");
for(i=0;i<n;++i)
scanf("%d",&arr[i]);
printf("nEnter the element to search: ");
scanf("%d",&x);
first=0;
last=n-1;
while(first<=last)
{
mid=(first+last)/2;
if(x==arr[mid]){
flag=1;
break;
}
else
if(x>arr[mid])
first=mid+1;
else
last=mid-1;
}
if(flag==1)
printf("nElement found at position %d",mid+1);
else
printf("nElement not found");
return 0;
}
Program of Push and Pop operations in stack using the application of string
#include<stdio.h>
typedef struct stack
{
char data[100]; int top;
}stack;
int empty(stack *p)
{
return (p->top==-1);
}
int top(stack *p)
{
return p->data[p->top];
}
void push(stack *p,char x)
{
p->data[++(p->top)]= x;
}
void pop(stack *p)
{
if(!empty(p))
{
p->top = p->top - 1 ;
}
}
int main()
{
stack s; s.top = -1; char str[100];
printf("Enter the string = "); fgets(str,sizeof(str),stdin); int i, len = sizeof(str);
for(i=0;i<len;i++)
{
push(&s,str[i]);
}
printf("nReverse string is n");
while(!empty(&s))
{
printf("%c",top(&s));
pop(&s);
}
}
Program of Quick Sort
#include<stdio.h>
void quicksort(int number[25],int first,int last){
int i, j, pivot, temp;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(number[i]<=number[pivot]&&i<last)
i++;
while(number[j]>number[pivot])
j--;
if(i<j){
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
temp=number[pivot];
number[pivot]=number[j];
number[j]=temp;
quicksort(number,first,j-1);
quicksort(number,j+1,last);
}
}
int main(){
int i, count, number[25];
printf("Enter the number of term you want to insert: ");
scanf("%d",&count);
printf("Enter %d elements: n", count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
quicksort(number,0,count-1);
printf("Order of Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}
Program for Infix to Postfix Evaluation
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#define SIZE 100
char stack[SIZE];
int top = -1;
void push(char item)
{
if(top<SIZE-1)
{
top=top+1;
stack[top]=item;
}
else
{
printf("Stack Overflow");
return;
}
}
char pop()
{
char item;
if(top<0)
{
printf("Stack Underflow");
}
else
{
item=stack[top];
top=top-1;
return item;
}
}
int is_operator(char symbol)
{
if(symbol == '^' || symbol == '*' || symbol == '/' || symbol == '+' || symbol =='-')
{
return 1;
}
else
{
return 0;
}
}
int precedence(char symbol)
{
if(symbol == '^')
{
return(3);
}
else if(symbol == '*' || symbol == '/')
{
return(2);
}
else if(symbol == '+' || symbol == '-')
{
return(1);
}
else
{
return(0);
}
}
void InfixToPostfix(char infix_exp[], char postfix_exp[])
{
int i, j;
char item;
char x;
push('(');
strcat(infix_exp,")");
i=0;
j=0;
item=infix_exp[i];
while(item != '0')
{
if(item == '(')
{
push(item);
}
else if( isdigit(item) || isalpha(item))
{
postfix_exp[j] = item;
j++;
}
else if(is_operator(item) == 1)
{
x=pop();
while(is_operator(x) == 1 && precedence(x)>= precedence(item))
{
postfix_exp[j] = x;
j++;
x = pop();
}
push(x);
push(item);
}
else if(item == ')')
{
x = pop();
while(x != '(')
{
postfix_exp[j] = x;
j++;
x = pop();
}
}
else
{
printf("nInvalid infix Expression.n");
}
i++;
item = infix_exp[i];
}
if(top>0)
{
printf("nInvalid infix Expression.n");
}
postfix_exp[j] = '0';
}
int main()
{
char infix[SIZE], postfix[SIZE];
printf("nEnter Infix expression : ");
gets(infix);
InfixToPostfix(infix, postfix);
printf("Postfix Expression: ");
puts(postfix);
return 0;
}
Program for Postfix Evaluation
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
void push(long int character);
long int postfix_evaluation();
int pop();
int isEmpty();
int top;
long int stack[50];
char postfix_expression[50];
int main()
{
long int evaluated_value;
top = -1;
printf("nEnter an Expression in Postfix format:t");
scanf("%[^n]s", postfix_expression);
printf("nExpression in Postfix Format: t%sn", postfix_expression);
evaluated_value = postfix_evaluation();
printf("nEvaluation of Postfix Expression: t%ldn", evaluated_value);
return 0;
}
long int postfix_evaluation()
{
long int x, y, temp, value;
int count;
for(count = 0; count < strlen(postfix_expression); count++)
{
if(postfix_expression[count] <= '9' && postfix_expression[count] >= '0')
{
push(postfix_expression[count] - '0');
}
else
{
x = pop();
y = pop();
switch(postfix_expression[count])
{
case '+': temp = y + x;
break;
case '-': temp = y - x;
break;
case '*': temp = y * x;
break;
case '/': temp = y / x;
break;
case '%': temp = y % x;
break;
case '^': temp = pow(y, x);
break;
default: printf("Invalid");
}
push(temp);
}
}
value = pop();
return value;
}
void push(long int character)
{
if(top > 50)
{
printf("Stack Overflown");
exit(1);
}
top = top + 1;
stack[top] = character;
}
int pop()
{
if(isEmpty())
{
printf("Stack is Emptyn");
exit(1);
}
return(stack[top--]);
}
int isEmpty()
{
if(top == -1)
{
return 1;
}
else
{
return 0;
}
}
Program for Tower of Hanoi
#include <stdio.h>
void towers(int, char, char, char);
int main()
{
int num;
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :n");
towers(num, 'A', 'C', 'B');
return 0;
}
void towers(int num, char frompeg, char topeg, char auxpeg)
{
if (num == 1)
{
printf("n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
towers(num - 1, frompeg, auxpeg, topeg);
printf("n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
towers(num - 1, auxpeg, topeg, frompeg);
}
Program for Circular Queue
#include <stdio.h>
#define size 5
void insertq(int[], int);
void deleteq(int[]);
void display(int[]);
int front = - 1;
int rear = - 1;
int main()
{
int n, ch;
int queue[size];
do
{
printf("nn Circular Queue:n1. Insert n2. Deleten3. Displayn0. Exit");
printf("nEnter Choice 0-3? : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("nEnter number: ");
scanf("%d", &n);
insertq(queue, n);
break;
case 2:
deleteq(queue);
break;
case 3:
display(queue);
break;
}
}while (ch != 0);
}
void insertq(int queue[], int item)
{
if ((front == 0 && rear == size - 1) || (front == rear + 1))
{
printf("queue is full");
return;
}
else if (rear == - 1)
{
rear++;
front++;
}
else if (rear == size - 1 && front > 0)
{
rear = 0;
}
else
{
rear++;
}
queue[rear] = item;
}
void display(int queue[])
{
int i;
printf("n");
if (front > rear)
{
for (i = front; i < size; i++)
{
printf("%d ", queue[i]);
}
for (i = 0; i <= rear; i++)
printf("%d ", queue[i]);
}
else
{
for (i = front; i <= rear; i++)
printf("%d ", queue[i]);
}
}
void deleteq(int queue[])
{
if (front == - 1)
{
printf("Queue is empty ");
}
else if (front == rear)
{
printf("n %d deleted", queue[front]);
front = - 1;
rear = - 1;
}
else
{
printf("n %d deleted", queue[front]);
front++;
}
}
Program of Insertion and Deletion operation in Queue
#include <stdio.h>
#include<stdlib.h>
#define MAX 50
int queue_array[MAX];
int rear = - 1;
int front = - 1;
void insert()
{
int add_item;
if (rear == MAX - 1)
printf("Queue Overflow n");
else
{
if (front == - 1)
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &add_item);
rear = rear + 1;
queue_array[rear] = add_item;
}
}
void del()
{
if (front == - 1 || front > rear)
{
printf("Queue Underflow n");
return ;
}
else
{
printf("Element deleted from queue is : %dn", queue_array[front]);
front = front + 1;
}
}
void display()
{
int i;
if (front == - 1)
printf("Queue is empty n");
else
{
printf("Queue is : n");
for (i = front; i <= rear; i++)
printf("%d ", queue_array[i]);
printf("n");
}
}
int main()
{
int choice;
while (1)
{
printf("1.Insert element to queue n");
printf("2.Delete element from queue n");
printf("3.Display all elements of queue n");
printf("4.Quit n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice n");
}
}
}

Weitere ähnliche Inhalte

Was ist angesagt?

Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manualSANTOSH RATH
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)vinay arora
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project FileDeyvessh kumar
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207Syed Tanveer
 

Was ist angesagt? (20)

Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C lab excellent
C lab excellentC lab excellent
C lab excellent
 
C programs
C programsC programs
C programs
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
programs
programsprograms
programs
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
1D Array
1D Array1D Array
1D Array
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Data struture lab
Data struture labData struture lab
Data struture lab
 

Ähnlich wie Pnno

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopMohammad Imam Hossain
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or notaluavi
 
C programming function
C  programming functionC  programming function
C programming functionargusacademy
 

Ähnlich wie Pnno (20)

ADA FILE
ADA FILEADA FILE
ADA FILE
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
week-21x
week-21xweek-21x
week-21x
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Ada file
Ada fileAda file
Ada file
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
week-5x
week-5xweek-5x
week-5x
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Ds
DsDs
Ds
 
C programming function
C  programming functionC  programming function
C programming function
 

Kürzlich hochgeladen

Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...nirzagarg
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabiaahmedjiabur940
 
怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制
怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制
怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制vexqp
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...gajnagarg
 
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATIONCapstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATIONLakpaYanziSherpa
 
怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制
怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制
怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制vexqp
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangeThinkInnovation
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...Elaine Werffeli
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNKTimothy Spann
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制vexqp
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubaikojalkojal131
 
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptxThe-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptxVivek487417
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样wsppdmt
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 

Kürzlich hochgeladen (20)

Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制
怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制
怎样办理伦敦大学毕业证(UoL毕业证书)成绩单学校原版复制
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATIONCapstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATION
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制
怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制
怎样办理纽约州立大学宾汉姆顿分校毕业证(SUNY-Bin毕业证书)成绩单学校原版复制
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptxThe-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
The-boAt-Story-Navigating-the-Waves-of-Innovation.pptx
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 

Pnno

  • 1. SUBMITTED TO SUBMITTED BY MOHIT SIR PARNEET KAUR MCA 2nd YEAR ROLL NO: 201880032 DEPARTMENT OF COMPUTER SCIENCE THAPAR INSTITUTE OF ENGINEERING TECHNOLOGY PATIALA
  • 2. LIST OF PROGRAMS Program of Insertion sort Program of Selection Sort Program of Bubble Sort Program of Merging two arrays Program of Multiplication of 2d Program of Linear Search Program of Binary Search Program of Push and Pop operations in stack using the application of string Program of Quick Sort Program of Infix to Postfix Evaluation Program of Postfix Evaluation Program of Tower of Hanoi Program of Circular Queue Program of Insertion and Deletion operation in Queue
  • 3. Program of insertion sort #include<stdio.h> int main() { int i, k, count, temp, number[100]; printf("Enter the number of the terms you want to insert: "); scanf("%d",&count); printf("Enter %d elements: n", count); for(i=0;i<count;i++) scanf("%d",&number[i]); for(i=1;i<count;i++){ temp=number[i]; k=i-1; while((temp<number[k])&&(k>=0)){ number[k+1]=number[k]; k=k-1; } number[k+1]=temp; } printf("Number in ascending order"); for(i=0;i<count;i++) printf(" %d",number[i]); return 0; }
  • 4. Program of Selection Sort #include<stdio.h> int main(){ int i, k, count, temp, number[40]; printf("Enter the number of terms you want to insert: "); scanf("%d",&count); printf("Enter %d elements:n", count); for(i=0;i<count;i++) scanf("%d",&number[i]); for(i=0;i<count;i++){ for(k=i+1;k<count;k++){ if(number[i]>number[k]){ temp=number[i]; number[i]=number[k]; number[k]=temp; } } } printf("Sorted elements: "); for(i=0;i<count;i++) printf(" %d",number[i]); return 0; }
  • 5. Program of Bubble Sort #include<stdio.h> int main(){ int count, temp, i, k, number[100]; printf("Enter the number of the terms you want to insert: "); scanf("%d",&count); printf("Enter %d numbers: n",count); for(i=0;i<count;i++) scanf("%d",&number[i]); for(i=count-2;i>=0;i--){ for(k=0;k<=i;k++){ if(number[k]>number[k+1]){ temp=number[k]; number[k]=number[k+1]; number[k+1]=temp; } } } printf("Sorted elements: "); for(i=0;i<count;i++) printf(" %d",number[i]); return 0; }
  • 6. Program of Merging two arrays #include <stdio.h> int main() { int array1[50], array2[50], array3[100], m, n, i, j, k = 0; printf("n Enter size of array Array 1: "); scanf("%d", &m); printf("n Enter sorted elements of array 1: n"); for (i = 0; i < m; i++) { scanf("%d", &array1[i]); } printf("n Enter size of array 2: "); scanf("%d", &n); printf("n Enter sorted elements of array 2: n"); for (i = 0; i < n; i++) { scanf("%d", &array2[i]); } i = 0; j = 0; while (i < m && j < n) { if (array1[i] < array2[j]) { array3[k] = array1[i]; i++; } else {
  • 7. array3[k] = array2[j]; j++; } k++; } if (i >= m) { while (j < n) { array3[k] = array2[j]; j++; k++; } } if (j >= n) { while (i < m) { array3[k] = array1[i]; i++; k++; } } printf("n After merging: n"); for (i = 0; i < m + n; i++) { printf("n%d", array3[i]); } }
  • 8. Program of Multiplication of 2d # include <stdio.h> # include <conio.h> int main() { int mata[10][10], matb[10][10], matc[10][10] ; int i, j, k, row1, col1, row2, col2 ; printf("Enter the order of first matrix : n") ; scanf("%d %d", &row1, &col1) ; printf("nEnter the order of second matrix : n") ; scanf("%d %d", &row2, &col2) ; if(col1 == row2) { printf("nEnter the elements of first matrix : nn") ; for(i = 0 ; i < row1 ; i++) for(j = 0 ; j < col1 ; j++) scanf("%d", &mata[i][j]) ; printf("nEnter the elements of second matrix : nn") ; for(i = 0 ; i < row2 ; i++) for(j = 0 ; j < col2 ; j++) scanf("%d", &matb[i][j]) ; for(i = 0 ; i < row1 ; i++) { for(j = 0 ; j < col2 ; j++) { matc[i][j] = 0 ; for(k = 0 ; k < col1 ; k++) matc[i][j] = matc[i][j] + mata[i][k] * matb[k][j] ; } } printf("nThe resultant matrix is : nn") ; for(i = 0 ; i < row1 ; i++) { for(j = 0 ; j < col2 ; j++) { printf("%d t", matc[i][j]) ; } printf("n") ; } } else printf("nMatrix Multiplication is not possible ...") ; getch() ; }
  • 9. Program of Linear Search #include<stdio.h> int main() { int a[20],i,x,n; printf("Enter the number of element should be available in array: "); scanf("%d",&n); printf("Enter array elements:n"); for(i=0;i<n;++i) scanf("%d",&a[i]); printf("nEnter element to search: "); scanf("%d",&x); for(i=0;i<n;++i) if(a[i]==x) break; if(i<n) printf("Element found at index %d",i); else printf("Element not found"); return 0; }
  • 10. Program of Binary Search #include<stdio.h> int main() { int arr[50],i,n,x,flag=0,first,last,mid; printf("Enter size of array: "); scanf("%d",&n); printf("nEnter array element(ascending order)n"); for(i=0;i<n;++i) scanf("%d",&arr[i]); printf("nEnter the element to search: "); scanf("%d",&x); first=0; last=n-1; while(first<=last) { mid=(first+last)/2; if(x==arr[mid]){ flag=1; break; } else if(x>arr[mid]) first=mid+1; else last=mid-1; } if(flag==1) printf("nElement found at position %d",mid+1); else printf("nElement not found"); return 0; }
  • 11. Program of Push and Pop operations in stack using the application of string #include<stdio.h> typedef struct stack { char data[100]; int top; }stack; int empty(stack *p) { return (p->top==-1); } int top(stack *p) { return p->data[p->top]; } void push(stack *p,char x) { p->data[++(p->top)]= x; } void pop(stack *p) { if(!empty(p)) { p->top = p->top - 1 ; } }
  • 12. int main() { stack s; s.top = -1; char str[100]; printf("Enter the string = "); fgets(str,sizeof(str),stdin); int i, len = sizeof(str); for(i=0;i<len;i++) { push(&s,str[i]); } printf("nReverse string is n"); while(!empty(&s)) { printf("%c",top(&s)); pop(&s); } }
  • 13. Program of Quick Sort #include<stdio.h> void quicksort(int number[25],int first,int last){ int i, j, pivot, temp; if(first<last){ pivot=first; i=first; j=last; while(i<j){ while(number[i]<=number[pivot]&&i<last) i++; while(number[j]>number[pivot]) j--; if(i<j){ temp=number[i]; number[i]=number[j]; number[j]=temp; } } temp=number[pivot]; number[pivot]=number[j]; number[j]=temp; quicksort(number,first,j-1); quicksort(number,j+1,last); } } int main(){ int i, count, number[25]; printf("Enter the number of term you want to insert: "); scanf("%d",&count); printf("Enter %d elements: n", count); for(i=0;i<count;i++) scanf("%d",&number[i]); quicksort(number,0,count-1);
  • 14. printf("Order of Sorted elements: "); for(i=0;i<count;i++) printf(" %d",number[i]); return 0; }
  • 15. Program for Infix to Postfix Evaluation #include<stdio.h> #include<ctype.h> #include<string.h> #define SIZE 100 char stack[SIZE]; int top = -1; void push(char item) { if(top<SIZE-1) { top=top+1; stack[top]=item; } else { printf("Stack Overflow"); return; } } char pop() { char item; if(top<0) { printf("Stack Underflow"); } else { item=stack[top]; top=top-1; return item; } } int is_operator(char symbol) { if(symbol == '^' || symbol == '*' || symbol == '/' || symbol == '+' || symbol =='-') { return 1; }
  • 16. else { return 0; } } int precedence(char symbol) { if(symbol == '^') { return(3); } else if(symbol == '*' || symbol == '/') { return(2); } else if(symbol == '+' || symbol == '-') { return(1); } else { return(0); } } void InfixToPostfix(char infix_exp[], char postfix_exp[]) { int i, j; char item; char x; push('('); strcat(infix_exp,")"); i=0; j=0; item=infix_exp[i]; while(item != '0') { if(item == '(') { push(item); }
  • 17. else if( isdigit(item) || isalpha(item)) { postfix_exp[j] = item; j++; } else if(is_operator(item) == 1) { x=pop(); while(is_operator(x) == 1 && precedence(x)>= precedence(item)) { postfix_exp[j] = x; j++; x = pop(); } push(x); push(item); } else if(item == ')') { x = pop(); while(x != '(') { postfix_exp[j] = x; j++; x = pop(); } } else { printf("nInvalid infix Expression.n"); } i++; item = infix_exp[i]; } if(top>0) { printf("nInvalid infix Expression.n"); } postfix_exp[j] = '0'; }
  • 18. int main() { char infix[SIZE], postfix[SIZE]; printf("nEnter Infix expression : "); gets(infix); InfixToPostfix(infix, postfix); printf("Postfix Expression: "); puts(postfix); return 0; }
  • 19. Program for Postfix Evaluation #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> void push(long int character); long int postfix_evaluation(); int pop(); int isEmpty(); int top; long int stack[50]; char postfix_expression[50]; int main() { long int evaluated_value; top = -1; printf("nEnter an Expression in Postfix format:t"); scanf("%[^n]s", postfix_expression); printf("nExpression in Postfix Format: t%sn", postfix_expression); evaluated_value = postfix_evaluation(); printf("nEvaluation of Postfix Expression: t%ldn", evaluated_value); return 0; } long int postfix_evaluation() { long int x, y, temp, value; int count; for(count = 0; count < strlen(postfix_expression); count++) { if(postfix_expression[count] <= '9' && postfix_expression[count] >= '0') { push(postfix_expression[count] - '0'); } else { x = pop(); y = pop(); switch(postfix_expression[count]) { case '+': temp = y + x;
  • 20. break; case '-': temp = y - x; break; case '*': temp = y * x; break; case '/': temp = y / x; break; case '%': temp = y % x; break; case '^': temp = pow(y, x); break; default: printf("Invalid"); } push(temp); } } value = pop(); return value; } void push(long int character) { if(top > 50) { printf("Stack Overflown"); exit(1); } top = top + 1; stack[top] = character; } int pop() { if(isEmpty()) { printf("Stack is Emptyn"); exit(1); } return(stack[top--]); } int isEmpty() { if(top == -1)
  • 22. Program for Tower of Hanoi #include <stdio.h> void towers(int, char, char, char); int main() { int num; printf("Enter the number of disks : "); scanf("%d", &num); printf("The sequence of moves involved in the Tower of Hanoi are :n"); towers(num, 'A', 'C', 'B'); return 0; } void towers(int num, char frompeg, char topeg, char auxpeg) { if (num == 1) { printf("n Move disk 1 from peg %c to peg %c", frompeg, topeg); return; } towers(num - 1, frompeg, auxpeg, topeg); printf("n Move disk %d from peg %c to peg %c", num, frompeg, topeg); towers(num - 1, auxpeg, topeg, frompeg); }
  • 23. Program for Circular Queue #include <stdio.h> #define size 5 void insertq(int[], int); void deleteq(int[]); void display(int[]); int front = - 1; int rear = - 1; int main() { int n, ch; int queue[size]; do { printf("nn Circular Queue:n1. Insert n2. Deleten3. Displayn0. Exit"); printf("nEnter Choice 0-3? : "); scanf("%d", &ch); switch (ch) { case 1: printf("nEnter number: "); scanf("%d", &n); insertq(queue, n); break; case 2: deleteq(queue); break; case 3: display(queue); break; } }while (ch != 0); } void insertq(int queue[], int item) { if ((front == 0 && rear == size - 1) || (front == rear + 1)) { printf("queue is full"); return;
  • 24. } else if (rear == - 1) { rear++; front++; } else if (rear == size - 1 && front > 0) { rear = 0; } else { rear++; } queue[rear] = item; } void display(int queue[]) { int i; printf("n"); if (front > rear) { for (i = front; i < size; i++) { printf("%d ", queue[i]); } for (i = 0; i <= rear; i++) printf("%d ", queue[i]); } else { for (i = front; i <= rear; i++) printf("%d ", queue[i]); } } void deleteq(int queue[]) { if (front == - 1) { printf("Queue is empty "); } else if (front == rear)
  • 25. { printf("n %d deleted", queue[front]); front = - 1; rear = - 1; } else { printf("n %d deleted", queue[front]); front++; } }
  • 26. Program of Insertion and Deletion operation in Queue #include <stdio.h> #include<stdlib.h> #define MAX 50 int queue_array[MAX]; int rear = - 1; int front = - 1; void insert() { int add_item; if (rear == MAX - 1) printf("Queue Overflow n"); else { if (front == - 1) front = 0; printf("Inset the element in queue : "); scanf("%d", &add_item); rear = rear + 1; queue_array[rear] = add_item; } } void del() { if (front == - 1 || front > rear) { printf("Queue Underflow n"); return ; } else { printf("Element deleted from queue is : %dn", queue_array[front]); front = front + 1; } } void display() { int i; if (front == - 1) printf("Queue is empty n"); else {
  • 27. printf("Queue is : n"); for (i = front; i <= rear; i++) printf("%d ", queue_array[i]); printf("n"); } } int main() { int choice; while (1) { printf("1.Insert element to queue n"); printf("2.Delete element from queue n"); printf("3.Display all elements of queue n"); printf("4.Quit n"); printf("Enter your choice : "); scanf("%d", &choice); switch (choice) { case 1: insert(); break; case 2: del(); break; case 3: display(); break; case 4: exit(1); default: printf("Wrong choice n"); } } }