dslab
dslab
SEMESTER: 3rd
DATE:25/11/2024
LAB PRACTICAL FILE CP
INDEX
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = data;
newNode->next = NULL;
return newNode;
newNode->next = head;
return newNode;
temp->next = newNode;
return head;
}
LAB PRACTICAL FILE CP
if (head->data == key) {
head = head->next;
free(temp);
return head;
temp->next = temp->next->next;
free(toDelete);
return head;
temp = temp->next;
printf("NULL\n");
int main() {
traverseList(head);
traverseList(head);
return 0;
OUTPUT
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
newNode->next = head;
return newNode;
temp->next = newNode;
LAB PRACTICAL FILE CP
newNode->prev = temp;
return head;
free(temp);
return head;
temp = temp->next;
printf("NULL\n");
int main() {
traverseList(head);
traverseList(head);
return 0;
OUTPUT:
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = data;
newNode->next = newNode;
return newNode;
newNode->next = head;
temp->next = newNode;
return newNode;
temp->next = newNode;
newNode->next = head;
return head;
free(head);
return NULL;
prev = temp;
temp = temp->next;
if (temp == head) {
head = head->next;
last->next = head;
} else {
prev->next = temp->next;
free(temp);
return head;
if (head == NULL) {
printf("List is empty\n");
return;
do {
temp = temp->next;
printf("\n");
int main() {
traverseList(head);
traverseList(head);
return 0;
OUTPUT:
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
header->next = NULL;
return header;
newNode->data = data;
newNode->next = NULL;
return newNode;
newNode->next = header->next;
header->next = newNode;
temp = temp->next;
temp->next = newNode;
temp = temp->next;
if (temp->next != NULL) {
temp->next = temp->next->next;
free(toDelete);
temp = temp->next;
printf("NULL\n");
int main() {
insertAtBeginning(header, 10);
insertAtBeginning(header, 20);
LAB PRACTICAL FILE CP
insertAtEnd(header, 30);
traverseList(header);
deleteNode(header, 20);
traverseList(header);
return 0;
OUTPUT:
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Term {
int coeff;
int exp;
};
newTerm->coeff = coeff;
newTerm->exp = exp;
newTerm->next = NULL;
return newTerm;
newTerm->next = *head;
*head = newTerm;
} else {
temp = temp->next;
temp->next->coeff += coeff;
free(newTerm);
LAB PRACTICAL FILE CP
} else {
newTerm->next = temp->next;
temp->next = newTerm;
temp = temp->next;
printf("\n");
int main() {
insertTerm(&poly, 5, 2);
insertTerm(&poly, 3, 1);
insertTerm(&poly, 4, 3);
insertTerm(&poly, 2, 0);
displayPolynomial(poly);
insertTerm(&poly, 6, 1);
displayPolynomial(poly);
return 0;
LAB PRACTICAL FILE CP
OUTPUT:
LAB PRACTICAL FILE CP
PROGRAM 6 :
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
#define K 3
int arr[MAX];
int top[K];
if (isFull(stackNum)) {
return;
top[stackNum]++;
if (isEmpty(stackNum)) {
return -1;
top[stackNum]--;
if (isEmpty(stackNum)) {
return -1;
if (isEmpty(stackNum)) {
return;
printf("\n");
int main() {
push(0, 10);
push(1, 20);
LAB PRACTICAL FILE CP
push(2, 30);
push(0, 40);
push(1, 50);
push(2, 60);
display(0);
display(1);
display(2);
display(1);
return 0;
OUTPUT:
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
#define MAX 3
struct Node {
int data;
};
struct Stack {
};
stacks[i].top = NULL;
newNode->data = value;
newNode->next = stack->top;
stack->top = newNode;
if (isEmpty(stack)) {
printf("Stack is empty\n");
return -1;
stack->top = stack->top->next;
free(temp);
return poppedValue;
if (isEmpty(stack)) {
printf("Stack is empty\n");
return -1;
return stack->top->data;
if (isEmpty(stack)) {
printf("Stack is empty\n");
return;
printf("Stack: ");
temp = temp->next;
printf("\n");
int main() {
initialize(stacks);
push(&stacks[0], 10);
push(&stacks[1], 20);
push(&stacks[2], 30);
push(&stacks[0], 40);
push(&stacks[1], 50);
push(&stacks[2], 60);
display(&stacks[0]);
display(&stacks[1]);
display(&stacks[2]);
display(&stacks[1]);
return 0;
}
LAB PRACTICAL FILE CP
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Stack {
char arr[MAX];
int top;
};
stack->top = -1;
if (isFull(stack)) {
printf("Stack Overflow\n");
return;
stack->arr[++stack->top] = value;
}
LAB PRACTICAL FILE CP
if (isEmpty(stack)) {
printf("Stack Underflow\n");
return -1;
return stack->arr[stack->top--];
return 0;
initialize(&stack);
push(&stack, expr[i]);
if (isEmpty(&stack)) {
return 0;
if (!isMatchingPair(top, expr[i])) {
return 0;
}
LAB PRACTICAL FILE CP
if (isEmpty(&stack)) {
return 1;
} else {
return 0;
int main() {
char expr[MAX];
scanf("%s", expr);
if (checkParenthesesBalance(expr)) {
} else {
return 0;
}
LAB PRACTICAL FILE CP
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
struct Stack {
char arr[MAX];
int top;
};
stack->top = -1;
if (isFull(stack)) {
printf("Stack Overflow\n");
return;
stack->arr[++stack->top] = value;
}
LAB PRACTICAL FILE CP
if (isEmpty(stack)) {
return -1;
return stack->arr[stack->top--];
if (isEmpty(stack)) {
return -1;
return stack->arr[stack->top];
int precedence(char c) {
if (c == '^') return 3;
return 0;
int isOperator(char c) {
initialize(&stack);
int i = 0, j = 0;
LAB PRACTICAL FILE CP
if (isalnum(infix[i])) {
} else if (isOperator(infix[i])) {
postfix[j++] = pop(&stack);
push(&stack, infix[i]);
i++;
while (!isEmpty(&stack)) {
postfix[j++] = pop(&stack);
postfix[j] = '\0';
int main() {
scanf("%s", infix);
LAB PRACTICAL FILE CP
infixToPostfix(infix, postfix);
return 0;
}
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
struct Stack {
char arr[MAX];
int top;
};
stack->top = -1;
if (isFull(stack)) {
printf("Stack Overflow\n");
return;
stack->arr[++stack->top] = value;
LAB PRACTICAL FILE CP
if (isEmpty(stack)) {
return -1;
return stack->arr[stack->top--];
if (isEmpty(stack)) {
return -1;
return stack->arr[stack->top];
int precedence(char c) {
if (c == '^') return 3;
return 0;
int isOperator(char c) {
exp[length - 1 - i] = temp;
initialize(&stack);
int i = 0, j = 0;
reverse(infix);
if (isalnum(infix[i])) {
prefix[j++] = infix[i];
push(&stack, infix[i]);
prefix[j++] = pop(&stack);
pop(&stack);
} else if (isOperator(infix[i])) {
prefix[j++] = pop(&stack);
push(&stack, infix[i]);
i++;
while (!isEmpty(&stack)) {
LAB PRACTICAL FILE CP
prefix[j++] = pop(&stack);
prefix[j] = '\0';
reverse(prefix);
int main() {
scanf("%s", infix);
infixToPrefix(infix, prefix);
return 0;
}
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
struct Queue {
int arr[MAX];
int front;
int rear;
};
q->front = -1;
q->rear = -1;
if (isFull(q)) {
printf("Queue Overflow\n");
return;
if (q->front == -1) {
LAB PRACTICAL FILE CP
q->front = 0;
q->arr[++(q->rear)] = value;
if (isEmpty(q)) {
printf("Queue Underflow\n");
return -1;
return value;
if (isEmpty(q)) {
printf("Queue is empty\n");
return;
printf("\n");
int main() {
struct Queue q;
initialize(&q);
LAB PRACTICAL FILE CP
enqueue(&q, 10);
enqueue(&q, 20);
enqueue(&q, 30);
enqueue(&q, 40);
enqueue(&q, 50);
display(&q);
display(&q);
enqueue(&q, 60);
display(&q);
return 0;
}
LAB PRACTICAL FILE CP
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
struct Queue {
};
q->front = NULL;
q->rear = NULL;
if (!newNode) {
return;
newNode->data = value;
newNode->next = NULL;
LAB PRACTICAL FILE CP
if (q->rear == NULL) {
} else {
q->rear->next = newNode;
q->rear = newNode;
if (isEmpty(q)) {
printf("Queue Underflow\n");
return -1;
q->front = q->front->next;
if (q->front == NULL) {
q->rear = NULL;
free(temp);
return value;
if (isEmpty(q)) {
printf("Queue is empty\n");
return;
temp = temp->next;
printf("\n");
int main() {
struct Queue q;
initialize(&q);
enqueue(&q, 10);
enqueue(&q, 20);
enqueue(&q, 30);
enqueue(&q, 40);
display(&q);
display(&q);
enqueue(&q, 50);
display(&q);
return 0;
}
LAB PRACTICAL FILE CP
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
int priority;
};
struct PriorityQueue {
};
pq->front = NULL;
if (!newNode) {
return;
newNode->data = value;
newNode->priority = priority;
newNode->next = NULL;
LAB PRACTICAL FILE CP
newNode->next = pq->front;
pq->front = newNode;
} else {
temp = temp->next;
newNode->next = temp->next;
temp->next = newNode;
if (isEmpty(pq)) {
return -1;
pq->front = pq->front->next;
free(temp);
return value;
if (isEmpty(pq)) {
return;
}
LAB PRACTICAL FILE CP
printf("Priority Queue:\n");
temp = temp->next;
int main() {
initialize(&pq);
display(&pq);
display(&pq);
display(&pq);
return 0;
}
LAB PRACTICAL FILE CP
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
if (!newNode) {
exit(1);
newNode->data = data;
newNode->next = NULL;
return newNode;
newNode = createNode(i);
if (head == NULL) {
head = newNode;
head->next = head;
} else {
LAB PRACTICAL FILE CP
temp = head;
temp = temp->next;
temp->next = newNode;
newNode->next = head;
return head;
prev = prev->next;
prev = curr;
curr = curr->next;
prev->next = curr->next;
free(curr);
curr = prev->next;
free(curr);
return survivor;
int main() {
int n, k;
scanf("%d", &n);
scanf("%d", &k);
return 0;
}
LAB PRACTICAL FILE CP
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
if (!newNode) {
exit(1);
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
if (root != NULL) {
inOrder(root->left);
inOrder(root->right);
if (root != NULL) {
preOrder(root->left);
preOrder(root->right);
if (root != NULL) {
postOrder(root->left);
postOrder(root->right);
int main() {
root->left = createNode(2);
root->right = createNode(3);
root->left->left = createNode(4);
root->left->right = createNode(5);
inOrder(root);
printf("\n");
preOrder(root);
printf("\n");
postOrder(root);
printf("\n");
return 0;
}
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
if (!newNode) {
exit(1);
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
if (root == NULL) {
return createNode(data);
}
LAB PRACTICAL FILE CP
return root;
if (root == NULL) {
return 0;
if (root->data == key) {
return 1;
if (root != NULL) {
inOrder(root->left);
inOrder(root->right);
if (root != NULL) {
preOrder(root->left);
preOrder(root->right);
}
LAB PRACTICAL FILE CP
if (root != NULL) {
postOrder(root->left);
postOrder(root->right);
int main() {
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
break;
case 2:
scanf("%d", &key);
if (search(root, key)) {
} else {
break;
case 3:
inOrder(root);
printf("\n");
break;
case 4:
preOrder(root);
printf("\n");
break;
case 5:
postOrder(root);
printf("\n");
break;
case 6:
exit(0);
default:
printf("Invalid choice!\n");
return 0;
LAB PRACTICAL FILE CP
OUTPUT:
LAB PRACTICAL FILE CP
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Automobile {
char type[50];
int year;
};
struct Node {
};
if (!newNode) {
exit(1);
strcpy(newNode->info.type, type);
newNode->info.year = year;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
if (root == NULL) {
LAB PRACTICAL FILE CP
return root;
root = root->left;
return root;
if (root == NULL) {
return root;
} else {
if (root->left == NULL) {
free(root);
return temp;
LAB PRACTICAL FILE CP
free(root);
return temp;
root->info = temp->info;
return root;
if (root != NULL) {
inOrder(root->left);
inOrder(root->right);
int main() {
char type[50];
while (1) {
scanf("%d", &choice);
LAB PRACTICAL FILE CP
switch (choice) {
case 1:
scanf("%d", &year);
break;
case 2:
scanf("%d", &year);
break;
case 3:
inOrder(root);
break;
case 4:
exit(0);
default:
printf("Invalid choice!\n");
return 0;
}
LAB PRACTICAL FILE CP