0% found this document useful (0 votes)
6 views23 pages

C Programs

The document contains multiple C programming code snippets for various data structures and algorithms, including infix to prefix conversion, circular queues, polynomial addition, stack operations, and sparse matrix representation. Each section provides code for specific functionalities, such as enqueueing and dequeueing in queues, pushing and popping in stacks, and performing polynomial operations. The document also includes user interaction prompts for entering expressions and managing data structures.

Uploaded by

alans90654
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views23 pages

C Programs

The document contains multiple C programming code snippets for various data structures and algorithms, including infix to prefix conversion, circular queues, polynomial addition, stack operations, and sparse matrix representation. Each section provides code for specific functionalities, such as enqueueing and dequeueing in queues, pushing and popping in stacks, and performing polynomial operations. The document also includes user interaction prompts for entering expressions and managing data structures.

Uploaded by

alans90654
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Infix to prefix Circular queue

#include <stdio.h> #include<stdio.h>


#include <ctype.h> int cq[20],front=-1,rear=-1,item,n;
#include <string.h> void enqueue(int item){
char stack[100]; if(front==(rear+1)%n){
int top = -1; printf("Circular Queue full\n");}
void push(char x) { else if(front==-1){
stack[++top] = x;} front =0;
char pop() { rear = (rear+1)%n;
if (top == -1) cq[rear]=item; }
return -1; else{
else rear = (rear+1)%n;
return stack[top--];} cq[rear]=item; }}
int priority(char x) { void dequeue(){
if (x == '(' || x == ')') if(front==-1){
return 0; printf("Circular Queue empty\n");}
else if (x == '^') else if(rear==front){
return 3; item = cq[front];
else if (x == '*' || x == '/') rear = -1;
return 2; front = -1;
else if (x == '+' || x == '-') printf("Deleted :%d\n",item); }
return 1; else{
return 0;} item = cq[front];
void strrev(char *str) { front = (front+1)%n;
int i, j; printf("Deleted :%d\n",item); }}
char temp; void display(){
for (i = 0, j = strlen(str) - 1; i < j; i++, j--) { if(front!=-1){
temp = str[i]; int i = front;
str[i] = str[j]; do{
str[j] = temp;}} printf("%d\t",cq[i]);
void main() { i = (i+1)%n;;}
char exp[100], Prefix[100]; while(i!=(rear+1)%n);
int i = 0, j = 0; printf("\n"); }
char num; else
printf("Enter the expression: "); printf("Queue Empty\n");}
scanf("%s", exp); void main(){
strrev(exp); int ch;
while (exp[i] != '\0') { printf("Enter the size of circular queue:");
if (isalnum(exp[i])) { scanf("%d",&n);
if (isdigit(exp[i])) { printf("Circular Queue Operations\n");
while (isdigit(exp[i])) { printf("1.Enqueue 2.Dequeue 3.Display 4.Exit\n");
Prefix[j++] = exp[i++]; } do{
Prefix[j++] = ' '; printf("Enter your choice:");
i--; } scanf("%d",&ch);
else { switch(ch){
Prefix[j++] = exp[i]; }} case 1:{
else if (exp[i] == ')') { printf("Enter the item:");
push(exp[i]); } scanf("%d",&item);
else if (exp[i] == '(') { enqueue(item);}
while ((num = pop()) != ')') { break;
Prefix[j++] = num; } } case 2:
else { dequeue();
while (top != -1 && priority(stack[top]) > priority(exp[i])) { break;
num = pop(); case 3:
Prefix[j++] = num; } display();
push(exp[i]);} break;
i++; } case 4:{
while (top != -1) { printf("Exiting...");
num = pop(); break;}} }
Prefix[j++] = num; } while(ch!=4);}
Prefix[j] = '\0';
strrev(Prefix);
printf("Prefix Expression: %s\n", Prefix);}
Infix to postfix Postfix evaluation
#include<stdio.h> #include<stdio.h>
#include<ctype.h> #include<ctype.h>
char stack[100]; #include<math.h>
int top = -1; int stack[100];
void push(char x) { int top = -1;
stack[++top] = x;} void push(char x) {
char pop() { stack[++top] = x;}
if (top == -1) char pop() {
return -1; if (top==-1)
else return -1;
return stack[top--];} else
int priority(char x) { return stack[top--];}
if (x == '(') void main() {
return 0; char Postfix[50];
else if (x=='^') int i = 0, n1, n2, n3;
return 3; printf("Enter the postfix expression: ");
else if (x == '*' || x == '/') scanf("%s", Postfix);
return 2; while (Postfix[i] != '\0') {
else if (x == '+' || x == '-') if (isdigit(Postfix[i])) {
return 1; push(Postfix[i] - 48); }
return 0;} else {
void main() { n1 = pop();
char exp[20]; n2 = pop();
char Postfix[20]; switch (Postfix[i]) {
int i = 0, j = 0; case '+':
printf("Enter the infix expression: "); n3 = n2 + n1;
scanf("%s", exp); break;
while (exp[i] != '\0') { case '-':
if (isalnum(exp[i])) { n3 = n2 - n1;
Postfix[j++] = exp[i]; } break;
else if (exp[i] == '(') { case '*':
push(exp[i]); } n3 = n2 * n1;
else if (exp[i] == ')') { break;
while (stack[top] != '(') { case '/':
Postfix[j++] = pop(); } n3 = n2 / n1;
pop(); } break;
else { case '^':
while (top != -1 && priority(stack[top]) >= priority(exp[i])) { n3 = (int)pow(n2,n1);
Postfix[j++] = pop(); } break; }
push(exp[i]); } push(n3); }
i++; } i++; }
while (top != -1) { printf("\nThe result of the postfix expression is: %d\n",
Postfix[j++] = pop(); } pop()); }
Postfix[j] = '\0';
printf("Postfix Expression: %s\n", Postfix); }
Polynomial addition Queue
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> int q[20],front=-1,rear=-1,item;
struct Term { void enqueue(int item,int n){
int coefficient; if(rear==n-1){
int exponent;}; printf("Queue full\n");}
void addPolynomials(struct Term poly1[], int n1, struct Term poly2[], else if(front==-1 && rear==-1){
int n2) { front=0;
int n = n1 + n2; q[++rear]=item; }
struct Term result[n]; else{
int i = 0, j = 0, k = 0; rear++;
while (i < n1 && j < n2) { q[rear]=item; } }
if (poly1[i].exponent > poly2[j].exponent) { int dequeue(){
result[k++] = poly1[i++]; if(front==-1){
} else if (poly1[i].exponent < poly2[j].exponent) { printf("Queue empty\n");}
result[k++] = poly2[j++]; else if(rear==front){
} else { item=q[front];
result[k].exponent = poly1[i].exponent; rear=-1;
result[k++].coefficient = poly1[i++].coefficient + front=-1;
poly2[j++].coefficient;}} printf("Deleted:%d\n",item); }
while (i < n1) { else{
result[k++] = poly1[i++]; } item=q[front];
while (j < n2) { front++;
result[k++] = poly2[j++]; } printf("Deleted:%d\n",item); }}
printf("Result of polynomial addition:\n"); void display(){
for (i = 0; i < k; i++) { if(front ==-1){
printf("%dx^%d ", result[i].coefficient, result[i].exponent); printf("Empty");}
if (i != k - 1) { else{
printf("+ "); } } for(int i=front;i<=rear;i++){
printf("\n");} printf("%d\t",q[i]);}}
void main() { printf("\n"); }
int n1, n2; void main(){
printf("Enter the number of terms in the first polynomial: "); int ch,n;
scanf("%d", &n1); printf("Enter the size of queue:");
struct Term poly1[n1]; scanf("%d",&n);
printf("Enter the terms of the first polynomial (coefficient printf("Queue Operations\n");
exponent): \n"); printf("1.Enqueue 2.Dequeue 3.Display 4.Exit\n");
for (int i = 0; i < n1; i++) { do{
scanf("%d %d", &poly1[i].coefficient, &poly1[i].exponent);} printf("Enter your choice:");
printf("Enter the number of terms in the second polynomial: scanf("%d",&ch);
"); switch(ch){
scanf("%d", &n2); case 1:{
struct Term poly2[n2]; printf("Enter the item:");
printf("Enter the terms of the second polynomial (coefficient scanf("%d",&item);
exponent): \n"); enqueue(item,n);}
for (int i = 0; i < n2; i++) { break;
scanf("%d %d", &poly2[i].coefficient, &poly2[i].exponent); } case 2:
addPolynomials(poly1, n1, poly2, n2);} dequeue();
break;
case 3:
display();
break;
case 4:{
printf("Exiting...");
break;}
default:
printf("Invalid choice");
break; }}
while(ch!=4); }
Stack Sparse matrix
#include<stdio.h> #include <stdio.h>
int top=-1,st[30],item,n; void main(){
void push(int item){ int r,c,sp[100][3];
if (top==n-1) { printf("Enter the number of rows and columns in the matrix:
printf("Stack overflow");} ");
else { scanf("%d%d", &r,&c);
top++; int matrix[r][c];
st[top]=item;}} printf("Enter elements in the matrix:\n");
int pop(){ for (int i = 0; i < r; i++) {
if (top==-1){ for (int j = 0; j < c; j++) {
printf("Stack underflow");} scanf("%d", &matrix[i][j]);} }
else { printf("Given Matrix\n");
item=st[top]; for (int i = 0; i < r; i++) {
printf("Popped item:%d",item); for (int j = 0; j < c; j++) {
top--;} printf("%d\t", matrix[i][j]);}
return item;} printf("\n");}
void display() { int p = 1;
if (top==-1){ sp[0][0] = r;
printf("Empty\n");} sp[0][1] = c;
else { sp[0][2] = 0;
printf("Current stack:\n"); for (int i = 0; i < r; i++) {
for(int i=0;i<=top;i++){ for (int j = 0; j < c; j++) {
printf("%d\t",st[i]);} if (matrix[i][j] != 0) {
printf("\n");}} sp[0][2] = sp[0][2] + 1;
void main(){ sp[p][0] = i;
int x,ch; sp[p][1] = j;
printf("Enter the size of the stack:"); sp[p][2] = matrix[i][j];
scanf("%d",&n); p++; }} }
printf("1.Push\t2.Pop\t3.Display\t4.Exit\n"); printf("\n\nRepresentation in tuple form\n");
while(ch!=4){ printf("Row\tColumn\tValue\n");
printf("Enter your choice:"); for (int i = 0; i <= sp[0][2]; i++) {
scanf("%d",&ch); printf("%d\t%d\t%d\n", sp[i][0], sp[i][1], sp[i][2]); }}
switch(ch) {
case 1: {
printf("Enter a number:");
scanf("%d",&x);
push(x);
break;}
case 2: {
pop();
break;}
case 3:{
display();
break;}
case 4:
printf("Exiting...\n");
break;
default:{
printf("Invalid input");
break; }}}}
Polynomial multiplication String reverse using stack
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <string.h>
struct Term {
int coefficient; #define MAX 100 // Maximum size of the stack
int exponent;};
void multiplyPolynomials(struct Term poly1[], int n1, struct Term char stack[MAX]; // Stack to hold characters
poly2[], int n2) { int top = -1; // Stack top initialized to -1
// Maximum possible terms in the result array can be n1 * n2
int maxSize = n1 * n2; // Function to push a character onto the stack
struct Term result[maxSize]; void push(char ch) {
// Initialize result array if (top == MAX - 1) {
int k = 0; printf("Stack Overflow\n");
// Multiply each term of poly1 with each term of poly2 } else {
for (int i = 0; i < n1; i++) { top++;
for (int j = 0; j < n2; j++) { stack[top] = ch;
int coeff = poly1[i].coefficient * poly2[j].coefficient; }
int expo = poly1[i].exponent + poly2[j].exponent; }

// Add the product to the result, combining like terms // Function to pop a character from the stack
int found = 0; char pop() {
for (int l = 0; l < k; l++) { if (top == -1) {
if (result[l].exponent == expo) { printf("Stack Underflow\n");
result[l].coefficient += coeff; return -1; // Return an invalid character when stack is empty
found = 1; } else {
break; } } char ch = stack[top];
// If no like term found, add the new term top--;
if (!found) { return ch;
result[k].coefficient = coeff; }
result[k].exponent = expo; }
k++;}}}
// Print the result polynomial int main() {
printf("Result of polynomial multiplication:\n"); char str[MAX];
for (int i = 0; i < k; i++) {
printf("%dx^%d", result[i].coefficient, result[i].exponent); // Read the string from the user
if (i != k - 1) { printf("Enter a string: ");
printf(" + "); gets(str); // Using gets to allow reading space-separated
} strings
}
printf("\n"); // Push each character of the string onto the stack
} for (int i = 0; i < strlen(str); i++) {
push(str[i]);
void main() { }
int n1, n2;
// Pop characters from the stack to get the reversed string
printf("Enter the number of terms in the first polynomial: "); printf("Reversed string: ");
scanf("%d", &n1); while (top != -1) {
struct Term poly1[n1]; printf("%c", pop());
printf("Enter the terms of the first polynomial (coefficient }
exponent): \n"); printf("\n");
for (int i = 0; i < n1; i++) {
scanf("%d %d", &poly1[i].coefficient, &poly1[i].exponent); return 0;
} }
printf("Enter the number of terms in the second
polynomial:");
scanf("%d", &n2);
struct Term poly2[n2];
printf("Enter the terms of the second polynomial (coefficient
exponent): \n");
for (int i = 0; i < n2; i++) {
scanf("%d %d", &poly2[i].coefficient, &poly2[i].exponent)}

multiplyPolynomials(poly1, n1, poly2, n2);}

Reverse a number using stack Function call (application of stack)


#include <stdio.h> #include<stdio.h>
int top = -1, stack[30], n;
#define MAX 100 // Maximum size of the stack // Push a function onto the call stack
void push(int functionNumber) {
int stack[MAX]; // Stack to hold digits if (top == n - 1) {
int top = -1; // Stack top initialized to -1 printf("Stack overflow\n");
} else {
// Function to push a digit onto the stack top++;
void push(int digit) { stack[top] = functionNumber;
if (top == MAX - 1) { printf("Function %d called\n", functionNumber); }}
printf("Stack Overflow\n"); // Pop a function from the call stack
} else { int pop() {
top++; if (top == -1) {
stack[top] = digit; printf("Stack underflow\n");
} return -1;
} } else {
int functionNumber = stack[top];
// Function to pop a digit from the stack printf("Function %d returned\n", functionNumber);
int pop() { top--;
if (top == -1) { return functionNumber; }}
printf("Stack Underflow\n"); // Display the current function call stack
return -1; void displayStack() {
} else { if (top == -1) {
int digit = stack[top]; printf("Call stack is empty\n");
top--; } else {
return digit; printf("Current call stack:\n");
} for (int i = 0; i <= top; i++) {
} printf("Function %d\t", stack[i]);}
printf("\n");}}
int main() { // Simulate function calls
int num; void function1();
void function2();
// Read the number from the user void function3();
printf("Enter a number: "); void function1() {
scanf("%d", &num); push(1); // Simulate calling function1
// Simulating function1 calling function2
// Handle negative numbers function2();
int isNegative = 0; pop(); // Simulate returning from function1
if (num < 0) { }
isNegative = 1;
num = -num; void function2() {
} push(2); // Simulate calling function2
// Simulating function2 calling function3
// Push each digit of the number onto the stack function3();
while (num != 0) { pop(); // Simulate returning from function2
int digit = num % 10; // Extract the last digit }
push(digit); // Push the digit onto the stack
num /= 10; // Remove the last digit from the number void function3() {
} push(3); // Simulate calling function3
// Function 3 does not call any other functions, it just returns
// Pop digits from the stack to get the reversed number pop(); // Simulate returning from function3
printf("Reversed number: "); }
if (isNegative) {
printf("-"); void main() {
} printf("Enter the maximum size of the call stack: ");
while (top != -1) { scanf("%d", &n); // Set the maximum size of the stack
printf("%d", pop());
} printf("Simulating function calls...\n");
printf("\n");
function1(); // Start by calling function1
return 0;
} printf("Final call stack state:\n");
displayStack(); // Display the final state of the stack
}
Two stacks using a single array
#include<stdio.h> void main() {
int x, ch, stackNum;
int top1 = -1, top2, st[30], item, n;
printf("Enter the size of the array: ");
void push1(int item) { scanf("%d", &n);
if (top1 == top2 - 1) {
printf("Stack 1 overflow\n"); top2 = n; // Initialize top2 to the end of the array
} else {
top1++; printf("1.Push\t2.Pop\t3.Display\t4.Exit\n");
st[top1] = item;
} while (ch != 4) {
} printf("Enter your choice: ");
scanf("%d", &ch);
void push2(int item) {
if (top2 == top1 + 1) { switch (ch) {
printf("Stack 2 overflow\n"); case 1: {
} else { printf("Enter stack number (1 or 2): ");
top2--; scanf("%d", &stackNum);
st[top2] = item; printf("Enter a number: ");
} scanf("%d", &x);
} if (stackNum == 1) {
push1(x);
int pop1() { } else if (stackNum == 2) {
if (top1 == -1) { push2(x);
printf("Stack 1 underflow\n"); } else {
return -1; printf("Invalid stack number\n");
} else { }
item = st[top1]; break;
printf("Popped item from Stack 1: %d\n", item); }
top1--; case 2: {
return item; printf("Enter stack number (1 or 2): ");
} scanf("%d", &stackNum);
} if (stackNum == 1) {
pop1();
int pop2() { } else if (stackNum == 2) {
if (top2 == n) { pop2();
printf("Stack 2 underflow\n"); } else {
return -1; printf("Invalid stack number\n");
} else { }
item = st[top2]; break;
printf("Popped item from Stack 2: %d\n", item); }
top2++; case 3: {
return item; printf("Enter stack number (1 or 2): ");
} scanf("%d", &stackNum);
} if (stackNum == 1) {
display1();
void display1() { } else if (stackNum == 2) {
if (top1 == -1) { display2();
printf("Stack 1 is empty\n"); } else {
} else { printf("Invalid stack number\n");
printf("Stack 1:\n"); }
for (int i = 0; i <= top1; i++) { break;
printf("%d\t", st[i]); }
} case 4:
printf("\n"); printf("Exiting...\n");
} break;
} default:
printf("Invalid input\n");
void display2() { break;
if (top2 == n) { }
printf("Stack 2 is empty\n"); }
} else { }
printf("Stack 2:\n");
for (int i = n - 1; i >= top2; i--) {
printf("%d\t", st[i]);
}
printf("\n");}}
Parentheses checker Customer service system using queue
#include<stdio.h> #include <stdio.h>
int front = -1, rear = -1, queue[30], n;
int top = -1, st[30], n; // Function to add a customer to the queue
void enqueue(int customerID) {
// Function to push an element onto the stack if (rear == n - 1) {
void push(char item) { printf("Queue overflow: Customer %d could not be added to
if (top == n - 1) { the queue\n", customerID);
printf("Stack overflow\n"); } else {
} else { if (front == -1) {
top++; front = 0; // First customer added}
st[top] = item; rear++;
} queue[rear] = customerID;
} printf("Customer %d added to the queue\n", customerID);}}
// Function to serve a customer from the queue
// Function to pop an element from the stack int dequeue() {
char pop() { if (front == -1) {
if (top == -1) { printf("Queue underflow: No customers to serve\n");
printf("Stack underflow\n"); return -1;
return -1; } else {
} else { int customerID = queue[front];
char item = st[top]; printf("Serving customer %d\n", customerID);
top--; front++;
return item;}} if (front > rear) {
// Function to check if parentheses are balanced front = rear = -1; // Reset queue if it becomes empty}
int isBalanced(char expression[]) { return customerID;}}
for (int i = 0; expression[i] != '\0'; i++) { // Function to display the current queue
char current = expression[i]; void displayQueue() {
// Push opening parentheses onto the stack if (front == -1) {
if (current == '(' || current == '{' || current == '[') { printf("Queue is empty\n");
push(current);} } else {
// Check closing parentheses printf("Current queue:\n");
else if (current == ')' || current == '}' || current == ']') { for (int i = front; i <= rear; i++) {
if (top == -1) { printf("Customer %d\t", queue[i]);}
return 0; // Unmatched closing parenthesis } printf("\n");
char lastOpened = pop(); }}
// Check for mismatched parentheses void main() {
if ((current == ')' && lastOpened != '(') || int customerID, choice;
(current == '}' && lastOpened != '{') || printf("Enter the maximum size of the queue: ");
(current == ']' && lastOpened != '[')) { scanf("%d", &n);
return 0; // Mismatched parenthesis }}} printf("Customer Service System:\n");
printf("1. Add Customer\t2. Serve Customer\t3. Display
// If stack is empty, parentheses are balanced Queue\t4. Exit\n");
if (top == -1) { while (1) {
return 1; // Balanced printf("Enter your choice: ");
} else { scanf("%d", &choice);
return 0; // Unbalanced switch (choice) {
} case 1: {
} printf("Enter customer ID: ");
scanf("%d", &customerID);
void main() { enqueue(customerID);
char expression[30]; break;}
case 2: {
// Get input from user dequeue();
printf("Enter an expression with parentheses: "); break;}
scanf("%s", expression); case 3: {
displayQueue();
// Check if parentheses are balanced break;}
if (isBalanced(expression)) { case 4: {
printf("The parentheses are balanced.\n"); printf("Exiting...\n");
} else { return;}
printf("The parentheses are not balanced.\n"); default: {
} printf("Invalid input\n");
} break;
}}}}
Sparse transpose
#include <stdio.h>
void main() {
int r, c, sp[100][3], trans[100][3];
// Input rows and columns
printf("Enter the number of rows and columns in the matrix: ");
scanf("%d%d", &r, &c);
// Declare matrix of size r x c
int matrix[r][c];
// Input the elements of the matrix
printf("Enter elements in the matrix:\n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%d", &matrix[i][j]); } }
// Display the given matrix
printf("\nGiven Matrix\n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
printf("%d\t", matrix[i][j]); }
printf("\n");}
// Sparse matrix conversion
int p = 1;
sp[0][0] = r;
sp[0][1] = c;
sp[0][2] = 0; // Initialize non-zero element count to 0
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (matrix[i][j] != 0) {
sp[0][2] += 1; // Increment non-zero count
sp[p][0] = i; // Row index
sp[p][1] = j; // Column index
sp[p][2] = matrix[i][j]; // Non-zero element
p++; } } }
// Display the sparse matrix in tuple form
printf("\n\nRepresentation in tuple form\n");
printf("Row\tColumn\tValue\n");
for (int i = 0; i <= sp[0][2]; i++) {
printf("%d\t%d\t%d\n", sp[i][0], sp[i][1], sp[i][2]); }
// Transpose logic
int k = 1;
trans[0][0] = sp[0][1]; // Number of rows of the transposed matrix
trans[0][1] = sp[0][0]; // Number of columns of the transposed
matrix
trans[0][2] = sp[0][2]; // Number of non-zero elements

for (int i = 0; i < sp[0][1]; i++) { // Loop through columns


for (int j = 1; j <= sp[0][2]; j++) { // Loop through non-zero
elements
if (sp[j][1] == i) { // Check if column matches
trans[k][0] = sp[j][1]; // Row becomes column
trans[k][1] = sp[j][0]; // Column becomes row
trans[k][2] = sp[j][2]; // Value remains the same
k++;
}
}
}

// Display the transposed sparse matrix in tuple form


printf("\n\nTranspose in tuple form\n");
printf("Row\tColumn\tValue\n");
for (int i = 0; i <= trans[0][2]; i++) {
printf("%d\t%d\t%d\n", trans[i][0], trans[i][1], trans[i][2]);
}
}
Double ended queue }
#include <stdio.h> printf("Deleted from rear: %d\n", item);
return item;
int deque[30], front = -1, rear = -1, n; }
}
// Insert element at the front
void insertFront(int item) { // Display the current deque using for loop
if ((front == 0 && rear == n - 1) || (front == rear + 1)) { void displayDeque() {
printf("Deque overflow\n"); if (front == -1) {
} else if (front == -1) { // First element insertion printf("Deque is empty\n");
front = rear = 0; } else {
deque[front] = item; printf("Current deque:\n");
} else if (front == 0) { for (int i = front; i != rear; i = (i + 1) % n) {
front = n - 1; printf("%d\t", deque[i]);
deque[front] = item; }
} else { printf("%d\t", deque[rear]); // Print the last element (at rear)
front--; printf("\n");
deque[front] = item; }
} }
}
void main() {
// Insert element at the rear int choice, x;
void insertRear(int item) { printf("Enter the size of the deque: ");
if ((front == 0 && rear == n - 1) || (front == rear + 1)) { scanf("%d", &n);
printf("Deque overflow\n");
} else if (rear == -1) { // First element insertion printf("Double-Ended Queue Operations:\n");
rear = front = 0; printf("1. Insert Front\t2. Insert Rear\t3. Delete Front\t4.
deque[rear] = item; Delete Rear\t5. Display\t6. Exit\n");
} else if (rear == n - 1) {
rear = 0; while (1) {
deque[rear] = item; printf("Enter your choice: ");
} else { scanf("%d", &choice);
rear++;
deque[rear] = item; switch (choice) {
} case 1:
} printf("Enter a number: ");
scanf("%d", &x);
// Delete element from the front insertFront(x);
int deleteFront() { break;
if (front == -1) { case 2:
printf("Deque underflow\n"); printf("Enter a number: ");
return -1; scanf("%d", &x);
} else { insertRear(x);
int item = deque[front]; break;
if (front == rear) { // Single element case case 3:
front = rear = -1; deleteFront();
} else if (front == n - 1) { break;
front = 0; case 4:
} else { deleteRear();
front++; break;
} case 5:
printf("Deleted from front: %d\n", item); displayDeque();
return item; break;
} case 6:
} printf("Exiting...\n");
return;
// Delete element from the rear default:
int deleteRear() { printf("Invalid input\n");
if (rear == -1) { }
printf("Deque underflow\n"); }
return -1; }
} else {
int item = deque[rear];
if (front == rear) { // Single element case
front = rear = -1;
} else if (rear == 0) {
rear = n - 1;
} else {
rear--;
Priority queue scanf("%d", &x);
#include <stdio.h> enqueue(x);
break;
int pq[30], front = -1, rear = -1, n; case 2:
dequeue();
// Insert an element into the priority queue based on priority break;
void enqueue(int item) { case 3:
if (rear == n - 1) { displayPQ();
printf("Priority Queue overflow\n"); break;
} else { case 4:
int i; printf("Exiting...\n");
if (rear == -1) { // First element insertion return;
front = rear = 0; default:
pq[rear] = item; printf("Invalid input\n");
} else { }
for (i = rear; i >= 0 && pq[i] > item; i--) { }
pq[i + 1] = pq[i]; }
}
pq[i + 1] = item;
rear++;
}
printf("Inserted %d into the priority queue\n", item);
}
}

// Remove an element from the front (highest priority)


int dequeue() {
if (front == -1) {
printf("Priority Queue underflow\n");
return -1;
} else {
int item = pq[front];
printf("Dequeued item: %d\n", item);
front++;
if (front > rear) {
front = rear = -1; // Reset the queue
}
return item;
}
}

// Display the current priority queue


void displayPQ() {
if (front == -1) {
printf("Priority Queue is empty\n");
} else {
printf("Current priority queue:\n");
for (int i = front; i <= rear; i++) {
printf("%d\t", pq[i]);
}
printf("\n");
}
}

void main() {
int choice, x;
printf("Enter the size of the priority queue: ");
scanf("%d", &n);

printf("Priority Queue Operations:\n");


printf("1. Enqueue\t2. Dequeue\t3. Display\t4. Exit\n");

while (1) {
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
printf("Enter a number: ");
Merge two stacks }
#include <stdio.h> }

int stack1[30], stack2[30], stack3[60], top1 = -1, top2 = -1, top3 = -1, void main() {
n1, n2; int x, ch;

// Push into stack1 // Input for first stack


void push1(int item) { printf("Enter the size of Stack 1: ");
if (top1 == n1 - 1) { scanf("%d", &n1);
printf("Stack1 overflow\n"); printf("Enter the elements for Stack 1:\n");
} else { for (int i = 0; i < n1; i++) {
stack1[++top1] = item; scanf("%d", &x);
} push1(x);
} }

// Push into stack2 // Input for second stack


void push2(int item) { printf("Enter the size of Stack 2: ");
if (top2 == n2 - 1) { scanf("%d", &n2);
printf("Stack2 overflow\n"); printf("Enter the elements for Stack 2:\n");
} else { for (int i = 0; i < n2; i++) {
stack2[++top2] = item; scanf("%d", &x);
} push2(x);
} }

// Push into merged stack3 // Merging stacks


void push3(int item) { mergeStacks();
stack3[++top3] = item;
} // Display merged stack
displayStack3();
// Pop from stack1 }
int pop1() {
if (top1 == -1) {
printf("Stack1 underflow\n");
return -1;
} else {
return stack1[top1--];
}
}

// Pop from stack2


int pop2() {
if (top2 == -1) {
printf("Stack2 underflow\n");
return -1;
} else {
return stack2[top2--];
}
}

// Merge two stacks into stack3


void mergeStacks() {
while (top1 != -1) {
push3(pop1());
}
while (top2 != -1) {
push3(pop2());
}
}

// Display merged stack3


void displayStack3() {
if (top3 == -1) {
printf("Merged stack is empty\n");
} else {
printf("Merged stack:\n");
for (int i = top3; i >= 0; i--) {
printf("%d\t", stack3[i]);
}
printf("\n");
Copy a stack to another stack
#include <stdio.h>

int stack1[30], stack2[30], top1 = -1, top2 = -1, n1;

// Push into stack1


void push1(int item) {
if (top1 == n1 - 1) {
printf("Stack1 overflow\n");
} else {
stack1[++top1] = item;
}
}

// Push into stack2 (for copying)


void push2(int item) {
stack2[++top2] = item;
}

// Pop from stack1


int pop1() {
if (top1 == -1) {
printf("Stack1 underflow\n");
return -1;
} else {
return stack1[top1--];
}
}

// Copy elements from stack1 to stack2


void copyStack() {
for (int i = 0; i <= top1; i++) {
push2(stack1[i]);
}
}

// Display stack2
void displayStack2() {
if (top2 == -1) {
printf("Copied stack is empty\n");
} else {
printf("Copied stack:\n");
for (int i = top2; i >= 0; i--) {
printf("%d\t", stack2[i]);
}
printf("\n");
}
}

void main() {
int x;

// Input for first stack


printf("Enter the size of Stack 1: ");
scanf("%d", &n1);
printf("Enter the elements for Stack 1:\n");
for (int i = 0; i < n1; i++) {
scanf("%d", &x);
push1(x);
}

// Copy stack1 to stack2


copyStack();

// Display copied stack


displayStack2();
}
Stack using ll Queue using ll
#include<stdio.h> #include<stdio.h>
#include<stdlib.h> #include<stdlib.h>
typedef struct Node{ typedef struct Node{
int data; int data;
struct Node *link; struct Node *link;
}node; }node;
node *top =NULL; node *front =NULL;
void push(int data){ node *rear =NULL;
node * new = (node*)malloc(sizeof(node)); void enqueue(int data){
if(new==NULL){ node * new = (node*)malloc(sizeof(node));
printf("Memory underflow\n");} if(new==NULL){
new->data=data; printf("Memory underflow\n");}
new->link=top; new->data=data;
top=new; new->link=NULL;
printf("%d pushed to stack\n",data);} if(rear==NULL){
int pop(){ front=rear=new;}
if(top==NULL){ else{
printf("Stack underflow\n"); rear->link=new;
return -1;} rear=new;
else{ printf("%d enqueued to queue\n",data);}}
node *temp=top; int dequeue(){
int item=temp->data; if(front==NULL){
top=top->link; printf("queue underflow\n");
free(temp); return -1;}
return item;}} else{
void display(){ node *temp=front;
if(top==NULL) int item=temp->data;
printf("Empty\n"); front=front->link;
else{ if(front==NULL){
node *ptr=top; rear=NULL;}
printf("Stack elements\n"); free(temp);
while(ptr!=NULL){ return item;}}
printf("%d\t",ptr->data); void display(){
ptr=ptr->link;} if(front==NULL)
printf("\n");}} printf("Empty\n");
void main(){ else{
int ch,data,p; node *ptr=front;
printf("1.Push\t2.Pop\t3.Display\t4.Exit\n"); printf("Queue elements\n");
while(ch!=4){ while(ptr!=NULL){
printf("Enter choice:"); printf("%d\t",ptr->data);
scanf("%d",&ch); ptr=ptr->link;}
switch(ch){ printf("\n");}}
case 1:{ void main(){
printf("Enter the data:"); int ch,data,p;
scanf("%d",&data); printf("1.Enqueue\t2.Dequeue\t3.Display\t4.Exit\n");
push(data); while(ch!=4){
break;} printf("Enter choice:");
case 2:{ scanf("%d",&ch);
data=pop(); switch(ch){
if(data!=-1) case 1:{
printf("Popped:%d\n",data); printf("Enter the data:");
break;} scanf("%d",&data);
case 3:{ enqueue(data);
display(); break;}
break;} case 2:{
case 4:{ data=dequeue();
printf("Exiting..."); if(data!=-1)
break;}}}} printf("Dequeued:%d\n",data);
break;}
case 3:{
display();
break;}
case 4:{
printf("Exiting...");
break;}}}}
Polynomial addition using ll Polynomial multiplication using ll
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
struct node { struct Node{
int coef; int coeff;
int exp; int pow;
struct node *link; struct Node* next;
}; };
struct node *poly1 = NULL; struct Node* poly1 = NULL;
struct node *poly2 = NULL; struct Node* poly2 = NULL;
struct node *result = NULL; struct Node* result = NULL;
struct node *createNode(){ struct Node* createNode(){
int coef,exp; int coeff, pow;
printf("Enter coeff: "); printf("Enter the coeff:");
scanf("%d",&coef); scanf("%d", &coeff);
printf("Enter exp: "); printf("Enter the power:");
scanf("%d",&exp); scanf("%d", &pow);
struct node *new = (struct node*)malloc(sizeof(struct node)); struct Node* newNode = (struct Node*)malloc(sizeof(struct
new->coef = coef; Node));
new->exp = exp; newNode->coeff = coeff;
new->link = NULL; newNode->pow = pow;
return new; } newNode->next = NULL;
void insertNode(struct node **poly){ return newNode;}
struct node *new = createNode(); void insertNode(struct Node** poly){
if(*poly == NULL) struct Node* newNode = createNode();
*poly = new; if (*poly == NULL){
else{ *poly = newNode; }
struct node *temp = *poly; else{
while(temp->link != NULL) struct Node* temp = *poly;
temp = temp->link; while (temp->next != NULL){
temp->link = new; }} temp = temp->next; }
void addNode(struct node *p){ temp->next = newNode; }}
struct node *new = (struct node*)malloc(sizeof(struct node)); void multiplyPolynomials(){
new->coef = p->coef; struct Node* p1 = poly1;
new->exp = p->exp; struct Node* p2 = poly2;
new->link = NULL; struct Node* temp;
if(result == NULL) while (p1 != NULL){
result = new; p2 = poly2;
else{ while (p2 != NULL){
struct node *temp = result; int coeff = p1->coeff * p2->coeff;
while(temp->link != NULL) int pow = p1->pow + p2->pow;
temp= temp->link; struct Node* newNode = (struct Node*)malloc(sizeof(struct
temp->link = new; }} Node));
void add(){ newNode->coeff = coeff;
struct node *p1 = poly1; newNode->pow = pow;
struct node *p2 = poly2; newNode->next = NULL;
while(p1 != NULL && p2 != NULL){ if (result == NULL){
if(p1->exp > p2->exp){ result = newNode;
addNode(p1); }
p1 = p1->link; else{
}else if(p1->exp < p2->exp){ temp = result;
addNode(p2); struct Node* prev = NULL;
p2=p2->link; } while (temp != NULL && temp->pow > pow){
else{ prev = temp;
int sum = p1->coef + p2->coef; temp = temp->next; }
if(sum !=0){ if (temp != NULL && temp->pow == pow){
struct node *new = (struct node*)malloc(sizeof(struct node)); temp->coeff += coeff;
new->coef = sum; free(newNode); }
new->exp = p1->exp; else{
new->link = NULL; newNode->next = temp;
if(result == NULL){ if (prev == NULL){
result=new; result = newNode;}
}else{ else{
struct node *temp = result; prev->next = newNode; }}}
while(temp->link != NULL) p2 = p2->next; }
temp= temp->link; p1 = p1->next; }}
temp->link = new; }} void displayPolynomial(struct Node* poly){
p1=p1->link; while (poly != NULL){
p2=p2->link; }} printf("%dx^%d", poly->coeff, poly->pow);
while(p1 != NULL){ poly = poly->next;
addNode(p1); if (poly != NULL){
p1=p1->link; } printf(" + "); }}
while(p2 != NULL){ printf("\n"); }
addNode(p2); void main(){
p2=p2->link; }} int terms, i;
void display(struct node *poly){ printf("Enter the number of terms in first polynomial: ");
while(poly != NULL){ scanf("%d", &terms);
printf("%dX^%d",poly->coef,poly->exp); for (i = 0; i < terms; i++){
poly=poly->link; printf("Enter terms %d for the first polynomial\n", i + 1);
if(poly != NULL) insertNode(&poly1); }
printf(" + "); } printf("Enter the number of terms in second polynomial: ");
printf("\n"); } scanf("%d", &terms);
void main(){ for (i = 0; i < terms; i++){
int terms,i; printf("Enter terms %d for the second polynomial\n", i + 1);
printf("Enter the no. of terms of 1st poly: "); insertNode(&poly2); }
scanf("%d",&terms); printf("First polynomial: ");
for(i=0;i<terms;i++){ displayPolynomial(poly1);
insertNode(&poly1); } printf("Second polynomial: ");
printf("Enter the no. of terms of 2nd poly: "); displayPolynomial(poly2);
scanf("%d",&terms); multiplyPolynomials();
for(i=0;i<terms;i++){ printf("Product of Polynomials: ");
insertNode(&poly2); } displayPolynomial(result); }
printf("1st poly is: ");
display(poly1);
printf("2nd poly is: ");
display(poly2);
add();
printf("Sum : ");
display(result); }
Linked list operations if (head == NULL)
#include <stdio.h> printf("Empty\n");
#include <stdlib.h> else if (head->link == NULL) {
struct Node { free(head);
int data; head = NULL;
struct Node *link; } else {
}; struct Node *ptr = head;
int i; struct Node *ptr1 = head;
struct Node *head = NULL; while (ptr->link != NULL) {
void insertion_B(int data) { ptr1 = ptr;
struct Node *newnode = (struct Node*) ptr = ptr->link;}
malloc(sizeof(struct Node)); ptr1->link = NULL;
if (newnode == NULL) { free(ptr);}}
printf("Memory underflow\n"); void delete_I(int p) {
return;} if (p < 1 || p > count()) {
newnode->data = data; printf("Invalid position\n");
newnode->link = head; return;}
head = newnode;} if (p == 1)
int count() { delete_B();
int c = 0; else if (p == count())
struct Node *ptr = head; delete_E();
while (ptr != NULL) { else {
c++; struct Node *ptr = head;
ptr = ptr->link;} for (i = 1; i < p - 1; i++)
return c;} ptr = ptr->link;
void insertion_E(int data) { struct Node *temp = ptr->link;
struct Node *newnode = (struct Node*) ptr->link = temp->link;
malloc(sizeof(struct Node)); free(temp);}}
if (newnode == NULL) { void display() {
printf("Memory underflow\n"); if (head == NULL)
return;} printf("Empty\n");
if (head == NULL) { else {
newnode->data = data; struct Node *ptr = head;
newnode->link = NULL; while (ptr != NULL) {
head = newnode; printf("%d\t", ptr->data);
} else { ptr = ptr->link;}
struct Node *ptr = head; printf("\n"); }}
while (ptr->link != NULL) void main() {
ptr = ptr->link; int ch = 0, data, p;
newnode->data = data; printf("1. Insert at Beginning\n2. Insert at End\n3.
newnode->link = NULL; Delete at Beginning\n4. Delete at End\n5. Insertion at
ptr->link = newnode;}} Position\n6. Deletion at Position\n7. Display\n8.
void insertion_I(int data, int p) { Exit\n");
if (p < 1 || p > count() + 1) { while (ch != 8) {
printf("Invalid position\n"); printf("Select: ");
return;} scanf("%d", &ch);
if (p == 1) switch (ch) {
insertion_B(data); case 1:
else if (p == count() + 1) printf("Enter the element: ");
insertion_E(data); scanf("%d", &data);
else { insertion_B(data);
struct Node *newnode = (struct Node*)malloc(sizeof(struct Node)); break;
if (newnode == NULL) { case 2:
printf("Memory underflow\n"); printf("Enter the element: ");
return;} scanf("%d", &data);
struct Node *ptr = head; insertion_E(data);
for (i = 1; i < p - 1; i++) break;
ptr = ptr->link; case 3:
newnode->data = data; delete_B();
newnode->link = ptr->link; break;
ptr->link = newnode;}} case 4:
void delete_B() { delete_E();
if (head == NULL) break;
printf("Empty\n"); case 5:
else { printf("Enter the element: ");
struct Node *ptr = head; scanf("%d", &data);
head = head->link; printf("Enter the position: ");
free(ptr);}} scanf("%d", &p);
void delete_E() { insertion_I(data, p);
break;
case 6:
printf("Enter the position: ");
scanf("%d", &p);
delete_I(p);
break;
case 7:
display();
break;
case 8:
printf("Exiting program\n");
break;
default:
printf("Invalid choice\n"); }}}
Double ll Circular ll
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

struct Node { struct Node {


int data; int data;
struct Node *llink; struct Node *link;
struct Node *rlink; };
}; struct Node *head = NULL;
int i; int i;
struct Node *head = NULL; void insertion_B(int data) {
void insertion_B(int data) { struct Node *newnode = (struct Node*)malloc(sizeof(struct
struct Node *newnode = (struct Node*)malloc(sizeof(struct Node));
Node)); if (newnode == NULL) {
if (newnode == NULL) { printf("Memory underflow\n");
printf("Memory underflow\n"); return;}
return;} newnode->data = data;
newnode->data = data; if (head == NULL) {
newnode->rlink = head; head = newnode;
newnode->llink = NULL; newnode->link = head;
if (head != NULL) { } else {
head->llink = newnode;} struct Node *ptr = head;
head = newnode;} while (ptr->link != head) {
int count() { ptr = ptr->link;}
int c = 0; newnode->link = head;
struct Node *ptr = head; ptr->link = newnode;
while (ptr != NULL) { head = newnode;}}
c++; int count() {
ptr = ptr->rlink;} if (head == NULL)
return c;} return 0;
void insertion_E(int data) { int c = 1;
struct Node *newnode = (struct Node*)malloc(sizeof(struct struct Node *ptr = head->link;
Node)); while (ptr != head) {
if (newnode == NULL) { c++;
printf("Memory underflow\n"); ptr = ptr->link;}
return;} return c;}
newnode->data = data; void insertion_E(int data) {
newnode->rlink = NULL; struct Node *newnode = (struct Node*)malloc(sizeof(struct
if (head == NULL) { Node));
newnode->llink = NULL; if (newnode == NULL) {
head = newnode; printf("Memory underflow\n");
} else { return;}
struct Node *ptr = head; newnode->data = data;
while (ptr->rlink != NULL) if (head == NULL) {
ptr = ptr->rlink; head = newnode;
ptr->rlink = newnode; newnode->link = head;
newnode->llink = ptr; }} } else {
void insertion_I(int data, int p) { struct Node *ptr = head;
if (p < 1 || p > count() + 1) { while (ptr->link != head) {
printf("Invalid position\n"); ptr = ptr->link;}
return;} ptr->link = newnode;
if (p == 1) newnode->link = head;}}
insertion_B(data); void insertion_I(int data, int p) {
else if (p == count() + 1) if (p < 1 || p > count() + 1) {
insertion_E(data); printf("Invalid position\n");
else { return;}
struct Node *newnode = (struct Node*)malloc(sizeof(struct if (p == 1) {
Node)); insertion_B(data);
if (newnode == NULL) { } else if (p == count() + 1) {
printf("Memory underflow\n"); insertion_E(data);
return;} } else {
struct Node *ptr = head; struct Node *newnode = (struct Node*)malloc(sizeof(struct
for (i = 1; i < p - 1; i++) Node));
ptr = ptr->rlink; if (newnode == NULL) {
newnode->data = data; printf("Memory underflow\n");
newnode->rlink = ptr->rlink; return;}
newnode->llink = ptr; struct Node *ptr = head;
ptr->rlink->llink = newnode; for (i = 1; i < p - 1; i++)
ptr->rlink = newnode;}} ptr = ptr->link;
void delete_B() { newnode->data = data;
if (head == NULL) { newnode->link = ptr->link;
printf("Empty\n"); ptr->link = newnode;}}
} else { void delete_B() {
struct Node *ptr = head; if (head == NULL) {
head = head->rlink; printf("Empty\n");
if (head != NULL) } else if (head->link == head) {
head->llink = NULL; free(head);
free(ptr); }} head = NULL;
void delete_E() { } else {
if (head == NULL) { struct Node *ptr = head;
printf("Empty\n"); while (ptr->link != head) {
} else if (head->rlink == NULL) { ptr = ptr->link;}
free(head); struct Node *temp = head;
head = NULL; ptr->link = head->link;
} else { head = head->link;
struct Node *ptr = head; free(temp);}}
while (ptr->rlink != NULL) void delete_E() {
ptr = ptr->rlink; if (head == NULL) {
ptr->llink->rlink = NULL; printf("Empty\n");
free(ptr); }} } else if (head->link == head) {
void delete_I(int p) { free(head);
if (p < 1 || p > count()) { head = NULL;
printf("Invalid position\n"); } else {
return;} struct Node *ptr = head;
if (p == 1) struct Node *ptr1 = head;
delete_B(); while (ptr->link != head) {
else if (p == count()) ptr1 = ptr;
delete_E(); ptr = ptr->link;}
else { ptr1->link = head;
struct Node *ptr = head; free(ptr);}}
for (i = 1; i < p; i++) void delete_I(int p) {
ptr = ptr->rlink; if (p < 1 || p > count()) {
ptr->llink->rlink = ptr->rlink; printf("Invalid position\n");
ptr->rlink->llink = ptr->llink; return;}
free(ptr); }} if (p == 1) {
void display() { delete_B();
if (head == NULL) } else if (p == count()) {
printf("Empty\n"); delete_E();
else { } else {
struct Node *ptr = head; struct Node *ptr = head;
while (ptr != NULL) { for (i = 1; i < p - 1; i++)
printf("%d\t", ptr->data); ptr = ptr->link;
ptr = ptr->rlink; } struct Node *temp = ptr->link;
printf("\n"); }} ptr->link = temp->link;
void main() { free(temp); }}
int ch = 0, data, p; void display() {
printf("1. Insert at Beginning\n2. Insert at End\n3. Delete at if (head == NULL) {
Beginning\n4. Delete at End\n5. Insertion at Position\n6. Deletion at printf("Empty\n");
Position\n7. Display\n8. Exit\n"); } else {
while (ch != 8) { struct Node *ptr = head;
printf("Select: "); do {
scanf("%d", &ch); printf("%d\t", ptr->data);
switch (ch) { ptr = ptr->link;
case 1: } while (ptr != head);
printf("Enter the element: "); printf("\n");}}
scanf("%d", &data); void main() {
insertion_B(data); int ch = 0, data, p;
break; printf("1. Insert at Beginning\n2. Insert at End\n3. Delete at
case 2: Beginning\n4. Delete at End\n5. Insertion at Position\n6. Deletion at
printf("Enter the element: "); Position\n7. Display\n8. Exit\n");
scanf("%d", &data); while (ch != 8) {
insertion_E(data); printf("Select: ");
break; scanf("%d", &ch);
case 3: switch (ch) {
delete_B(); case 1:
break; printf("Enter the element: ");
case 4: scanf("%d", &data);
delete_E(); insertion_B(data);
break; break;
case 5: case 2:
printf("Enter the element: "); printf("Enter the element: ");
scanf("%d", &data); scanf("%d", &data);
printf("Enter the position: "); insertion_E(data);
scanf("%d", &p); break;
insertion_I(data, p); case 3:
break; delete_B();
case 6: break;
printf("Enter the position: "); case 4:
scanf("%d", &p); delete_E();
delete_I(p); break;
break; case 5:
case 7: printf("Enter the element: ");
display(); scanf("%d", &data);
break; printf("Enter the position: ");
case 8: scanf("%d", &p);
printf("Exiting program\n"); insertion_I(data, p);
break; break;
default: case 6:
printf("Invalid choice\n"); }}} printf("Enter the position: ");
scanf("%d", &p);
delete_I(p);
break;
case 7:
display();
break;
case 8:
printf("Exiting program\n");
break;
default:
printf("Invalid choice\n"); }}}
Binary tree using array Binary tree using ll
BST

You might also like