Asd
Asd
#include <stdio.h>
return (i + 1);
}
// Driver code
int main() {
int arr[] = {9, 2, 5, 1, 7, 6, 8};
int n = sizeof(arr) / sizeof(arr[0]);
// Perform quicksort
quickSort(arr, 0, n - 1);
printf("Array sorted using Quicksort: ");
printArray(arr, n);
return 0;
}
LL display contents \\
#include <stdio.h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
struct Node* next;
};
// Driver code
int main() {
struct Node* head = NULL;
// Insert nodes
insertNode(&head, 4);
insertNode(&head, 7);
insertNode(&head, 2);
insertNode(&head, 9);
return 0;
}
insert anywhere in LL \\
#include <stdio.h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
struct Node* next;
};
// Driver code
int main() {
struct Node* head = NULL;
return 0;
}
delete anywhere in LL \\
#include <stdio.h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
struct Node* next;
};
// Driver code
int main() {
struct Node* head = NULL;
// Insert nodes
insertNodeAtBeginning(&head, 4);
insertNodeAtBeginning(&head, 7);
insertNodeAtBeginning(&head, 2);
insertNodeAtBeginning(&head, 9);
return 0;
}
// Node structure
struct Node {
int data;
struct Node* prev;
struct Node* next;
};
// Insert nodes
insertNodeAtEnd(&head, 4);
insertNodeAtEnd(&head, 7);
insertNodeAtEnd(&head, 2);
insertNodeAtEnd(&head, 9);
return 0;
}
// Node structure
struct Node {
int data;
struct Node* prev;
struct Node* next;
};
// Driver code
int main() {
struct Node* head = NULL;
// Insert nodes
insertNodeAtEnd(&head, 4);
insertNodeAtBeginning(&head, 7);
insertNodeAtEnd(&head, 2);
insertNodeAtLocation(&head, 9, 1);
return 0;
}
// Driver code
int main() {
struct Term* poly1 = NULL;
struct Term* poly2 = NULL;
printf("Polynomial 1: ");
displayPolynomial(poly1);
printf("Polynomial 2: ");
displayPolynomial(poly2);
return 0;
}
// Driver code
int main() {
struct Stack stack;
initializeStack(&stack);
push(&stack, 5);
push(&stack, 10);
push(&stack, 15);
displayStack(&stack);
pop(&stack);
displayStack(&stack);
return 0;
}
// Driver code
int main() {
struct Stack* stack = createStack(100);
push(stack, 5);
push(stack, 10);
push(stack, 15);
displayStack(stack);
pop(stack);
displayStack(stack);
destroyStack(stack);
return 0;
}
queues static \\
#include <stdio.h>
#define MAX_SIZE 100
// Driver code
int main() {
struct Queue queue;
initializeQueue(&queue);
enqueue(&queue, 5);
enqueue(&queue, 10);
enqueue(&queue, 15);
displayQueue(&queue);
dequeue(&queue);
displayQueue(&queue);
return 0;
}
queues dynamic \\
#include <stdio.h>
#include <stdlib.h>
if (isEmpty(queue)) {
queue->front = newNode;
queue->rear = newNode;
} else {
queue->rear->next = newNode;
queue->rear = newNode;
}
if (queue->front == NULL) {
queue->rear = NULL;
}
// Driver code
int main() {
struct Queue queue;
initializeQueue(&queue);
enqueue(&queue, 5);
enqueue(&queue, 10);
enqueue(&queue, 15);
displayQueue(&queue);
dequeue(&queue);
displayQueue(&queue);
destroyQueue(&queue);
return 0;
}
trees traversals \\
1st\\
#include <stdio.h>
#include <stdlib.h>
inorderTraversal(root->left);
printf("%d ", root->data);
inorderTraversal(root->right);
}
postorderTraversal(root->left);
postorderTraversal(root->right);
printf("%d ", root->data);
}
// Driver code
int main() {
struct Node* root = createNode(1);
root->left = createNode(2);
root->right = createNode(3);
root->left->left = createNode(4);
root->left->right = createNode(5);
return 0;
}
2nd\\
#include <stdio.h>
#include <stdlib.h>
return newNode;
}
// Breadth-First Search
void BFS(struct Node* start) {
struct Node* queue[100];
int front = 0;
int rear = -1;
// Depth-First Search
void DFS(struct Node* start) {
printf("Depth-First Search: ");
DFSHelper(start);
printf("\n");
}
// Driver code
int main() {
struct Node* node1 = createNode(1, 3);
struct Node* node2 = createNode(2, 2);
struct Node* node3 = createNode(3, 2);
struct Node* node4 = createNode(4, 1);
struct Node* node5 = createNode(5, 1);
addEdge(node1, node2);
addEdge(node1, node3);
addEdge(node1, node4);
addEdge(node2, node5);
BFS(node1);
DFS(node1);
return 0;
}
avl tree \\
#include <stdio.h>
#include <stdlib.h>
// Perform rotation
x->right = y;
y->left = T2;
// Update heights
y->height = max(height(y->left), height(y->right)) + 1;
x->height = max(height(x->left), height(x->right)) + 1;
// Perform rotation
y->left = x;
x->right = T2;
// Update heights
x->height = max(height(x->left), height(x->right)) + 1;
y->height = max(height(y->left), height(y->right)) + 1;
// Driver code
int main() {
struct Node* root = NULL;
return 0;
}
printf("\n");
// Driver code
int main() {
int numVertices;
printf("Enter the number of vertices in the graph: ");
scanf("%d", &numVertices);
int startVertex;
printf("Enter the starting vertex for traversal: ");
scanf("%d", &startVertex);
two dimensional matrix and obtain the Traversals on the graph using DFS and BFS
methods \\
#include <stdio.h>
#include <stdlib.h>
int main() {
int numVertices;
printf("Enter the number of vertices in the graph: ");
scanf("%d", &numVertices);
int startVertex;
printf("Enter the starting vertex for traversal: ");
scanf("%d", &startVertex);
return 0;
}