ds_slip
ds_slip
if (arr[mid] == key)
return mid;
else if (arr[mid] < key)
low = mid + 1;
else
high = mid - 1;
}
return -1; // Element not found
}
int main() {
int arr[] = {2, 4, 6, 8, 10, 12, 14};
int n = sizeof(arr) / sizeof(arr[0]);
int key = 10;
if (result != -1)
printf("Element found at index %d\n", result);
else
printf("Element not found\n");
return 0;
}
int pop() {
if (top == -1)
printf("Stack Underflow\n");
else
return stack[top--];
return -1; // Return -1 if underflow occurs
}
int empty() {
return top == -1;
}
int main() {
int choice, value;
do {
printf("\nStack Operations:\n");
printf("1. Push\n");
printf("2. Pop\n");
printf("3. Check if Empty\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter value to push: ");
scanf("%d", &value);
push(value);
break;
case 2:
pop();
break;
case 3:
if (empty())
printf("Stack is empty.\n");
else
printf("Stack is not empty.\n");
break;
case 4:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
}
} while (choice != 4);
return 0;
}
Slip 2
int main() {
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, n);
return 0;
}
Write a C program to create binary search tree (BST) of integer numbers and display its in- order traversal
#include <stdio.h>
#include <stdlib.h>
int main() {
struct Node* root = NULL;
int arr[] = {50, 30, 20, 40, 70, 60, 80};
int n = sizeof(arr) / sizeof(arr[0]);
return 0;
}
Slip 3
int main() {
int arr[] = {12, 11, 13, 5, 6};
int n = sizeof(arr) / sizeof(arr[0]);
insertionSort(arr, n);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
struct Node* next;
};
int main() {
// Creating first linked list: 1 -> 2 -> 3 -> 4 -> 6
struct Node* head1 = newNode(1);
head1->next = newNode(2);
head1->next->next = newNode(3);
head1->next->next->next = newNode(4);
head1->next->next->next->next = newNode(6);
// Find intersection
struct Node* intersection = getIntersection(head1, head2);
return 0;
}
Slip 4
return 0;
}
Write a C menu driven program to implement singly circular linked list of integers with Following operations: (20)
● Create
● Insert
● Delete
● Display
#include <stdio.h>
#include <stdlib.h>
do {
printf("\nMenu:\n");
printf("1. Create List\n");
printf("2. Insert\n");
printf("3. Delete\n");
printf("4. Display\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
head = createList();
break;
case 2:
printf("Enter value to insert: ");
scanf("%d", &value);
head = insertNode(head, value);
break;
case 3:
printf("Enter value to delete: ");
scanf("%d", &value);
head = deleteNode(head, value);
break;
case 4:
display(head);
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
}
} while (choice != 5);
return 0;
}
Slip 5
// Node structure
struct Node {
int data;
struct Node* next;
};
// Main function
int main() {
displayList(createLinkedList());
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
// Stack structure
struct Stack {
int top;
int items[MAX];
};
// Stack operations
struct Stack* createStack() {
struct Stack* s = malloc(sizeof(struct Stack));
s->top = -1;
return s;
}
int main() {
char expression[MAX];
printf("Enter a postfix expression: ");
fgets(expression, sizeof(expression), stdin);
printf("Result: %d\n", evaluatePostfix(expression));
return 0;
}
Slip 6
// Stack structure
struct Stack {
int top;
char items[MAX];
};
// Stack operations
struct Stack* createStack() {
struct Stack* s = (struct Stack*)malloc(sizeof(struct Stack));
s->top = -1;
return s;
}
// Pop all characters from the stack and replace the original string
for (int i = 0; i < length; i++) {
str[i] = pop(s);
}
}
int main() {
char str[MAX];
reverseString(str);
printf("Reversed string: %s\n", str);
return 0;
}
Write a C program to read the data from the file “employee.txt” which contains empno and empname and sort the data on
names alphabetically (use strcmp) using Bubble Sort.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Employee structure
struct Employee {
int empno;
char empname[MAX_NAME_LEN];
};
int main() {
FILE* file = fopen("employee.txt", "r");
if (!file) {
printf("Error opening file.\n");
return 1;
}
return 0;
}
Slip 7
#include <stdio.h>
#include <stdlib.h>
// Main function
int main() {
struct Node* head = NULL;
struct Node* tail = NULL;
int value;
Q.2) Write a C program to implement dynamic implementation of stack of integers with followingoperation:
a) push()
b) pop ()
c) isempty()
d) isfull()
e) display ()
#include <stdio.h>
#include <stdlib.h>
struct Stack {
int *array;
int top;
int capacity;
};
while (1) {
printf("\n1. Push\n2. Pop\n3. Is Empty\n4. Is Full\n5. Display\n6. Exit\n");
printf("Choose an operation: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter value to push: ");
scanf("%d", &value);
push(stack, value);
break;
case 2:
value = pop(stack);
if (value != -1) printf("Popped: %d\n", value);
break;
case 3:
printf(isEmpty(stack) ? "Stack is empty.\n" : "Stack is not empty.\n");
break;
case 4:
printf(isFull(stack) ? "Stack is full.\n" : "Stack is not full.\n");
break;
case 5:
display(stack);
break;
case 6:
free(stack->array);
free(stack);
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}
Slip 8
// Main function
int main() {
createAndDisplayDoublyLinkedList();
return 0;
}
// Main function
int main() {
printf("Create first linked list:\n");
struct Node* list1 = createLinkedList();
printf("Create second linked list:\n");
struct Node* list2 = createLinkedList();
Slip 16
Q.1) Write a C program to sort an integer array using a recursive binary search method.
#include <stdio.h>
int main() {
int arr[] = {34, 7, 23, 32, 5, 62};
int n = sizeof(arr) / sizeof(arr[0]);
return 0;
}
char stack[MAX];
int top = -1;
int main() {
char infix[MAX], postfix[MAX];
printf("Enter infix expression: ");
scanf("%s", infix);
infixToPostfix(infix, postfix);
printf("Postfix expression: %s\n", postfix);
return 0;
}
Slip 17
Q.1) Write a C program to sort an array of structure using bubblesort method. Consider an array of structure Employee
with details: emp_id, Name, Address. Sort on emp_id and display
the employee details. (10)
#include <stdio.h>
#include <string.h>
int main() {
int n = 3; // Number of employees
struct Employee employees[] = {
{102, "Alice", "123 Street"},
{101, "Bob", "456 Avenue"},
{103, "Charlie", "789 Boulevard"}
};
printf("Before sorting:\n");
display(employees, n);
bubbleSort(employees, n);
return 0;
}
Q.2) Write a C program to check whether an expression has correct pairs of parentheses, using Stack.
#include <stdio.h>
#include <string.h>
char stack[MAX];
int top = -1;
int main() {
char expr[MAX];
printf("Enter expression: ");
scanf("%s", expr);
if (isBalanced(expr))
printf("Balanced\n");
else
printf("Unbalanced\n");
return 0;
}
Slip 18
Q.1) Write a C program to display the city code of the corresponding city name using linear search method. The structure
is:
struct city
{
int city_code;
char name[40];
}
#include <stdio.h>
#include <string.h>
int main() {
struct city cities[] = {
{101, "NewYork"},
{102, "London"},
{103, "Paris"}
};
int n = sizeof(cities) / sizeof(cities[0]);
char target[30];
printf("Enter city name: ");
scanf("%s", target);
return 0;
}
Write C program to construct a graph using adjacency matrix and display its adjacency list
#include <stdio.h>
#include <stdlib.h>
int main() {
int vertices, edges, u, v;
int adjMatrix[MAX][MAX] = {0}; // Initialize the adjacency matrix with 0
return 0;
}
Slip 19
Q.1) Write a C program to create and display singly Linked List.
#include <stdio.h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
struct Node* next;
};
int main() {
struct Node* head = NULL;
return 0;
}
Write a C program to display addition of two polynomials using singly linked list.
#include <stdio.h>
#include <stdlib.h>
return sum;
}
int main() {
struct Node *poly1 = NULL, *poly2 = NULL, *sum = NULL;
// Display polynomials
printf("First Polynomial: ");
display(poly1);
// Add polynomials
sum = addPolynomials(poly1, poly2);
return 0;
}
Slip 20
int main() {
int array[] = {12, 11, 13, 5, 6};
int size = sizeof(array) / sizeof(array[0]);
insertionSort(array, size);
return 0;
}
int stack[MAX];
int top = -1;
int pop() {
return stack[top--];
}
int main() {
char expr[] = "231*+9-"; // Example postfix expression: (2 + (3 * 1)) - 9
printf("Result: %d\n", evaluatePostfix(expr));
return 0;
}