dsa 9 10 11
dsa 9 10 11
h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
struct node {
int key;
struct node *left, *right, *parent;
int dist;
};
if (root == NULL) {
root = newNode;
return;
}
r = root;
while (1) {
if (r->key > val) {
if (r->left) {
r = r->left;
} else {
r->left = newNode;
newNode->parent = r;
break;
}
} else {
if (r->right) {
r = r->right;
} else {
r->right = newNode;
newNode->parent = r;
break;
}
}
}
int main() {
int a[10] = {32, 23, 16, 35, 33, 71, 65, 20, 18, 24};
for (int i = 0; i < 10; i++) {
insert(a[i]);
}
if (isLeftistMinHeap(root))
printf("The tree is a Leftist Min Heap.\n");
else
printf("The tree is not a Leftist Min Heap.\n");
inorder(root);
return 0;
}
*****************************************************
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
struct node {
int key;
struct node *left, *right, *parent;
int dist;
};
queue[rear++] = h1;
struct node *current = h1;
while (h2) {
if (!current->right) {
current->right = h2;
h2->parent = current;
current = h2;
h2 = NULL;
} else {
queue[rear++] = current->right;
current->right = h2;
h2->parent = current;
current = h2;
h2 = h2->right;
current->right = NULL;
}
current->dist = calculateDistance(current);
if (front < rear) {
current = queue[front++];
}
}
return h1;
}
int main() {
struct node *root1 = NULL, *root2 = NULL;
return 0;
}
********************************************************************
#include <stdio.h>
#include <stdlib.h>
queue[rear++] = root;
int main() {
// Create a sample tree:
// 1
// / \
// 2 3
// / \ / \
// 4 5 6 7
struct Node* root = createNode(1);
root->left = createNode(2);
root->right = createNode(3);
root->left->left = createNode(4);
root->left->right = createNode(5);
root->right->left = createNode(6);
root->right->right = createNode(7);
printf("Breadth-First Traversal: ");
breadthFirstTraversal(root);
printf("\n");
return 0;
}
****************************************************
#include <stdio.h>
#include <stdlib.h>
struct Node {
int vertex;
struct Node* next;
};
struct Graph {
int numVertices;
struct Node** adjLists;
int* visited;
};
struct Stack {
int* array;
int top;
int max;
};
return graph;
}
// Stack operations
int isEmpty(struct Stack* stack) {
return stack->top == -1;
}
if (graph->visited[connectedVertex] == 0) {
topologicalSortUtil(graph, connectedVertex, stack);
}
temp = temp->next;
}
push(stack, vertex);
}
while (!isEmpty(stack)) {
printf("%d ", pop(stack));
}
printf("\n");
}
int main() {
struct Graph* graph = createGraph(6);
addEdge(graph, 5, 2);
addEdge(graph, 5, 0);
addEdge(graph, 4, 0);
addEdge(graph, 4, 1);
addEdge(graph, 2, 3);
addEdge(graph, 3, 1);
return 0;
}
**************************************************************
#include <stdio.h>
#include <stdlib.h>
#define TABLE_SIZE 10
// Hash function
int hashFunction(int key) {
return key % TABLE_SIZE;
}
// Display chain
void displayChaining() {
for (int i = 0; i < TABLE_SIZE; i++) {
struct Node* temp = chain[i];
printf("chain[%d] -> ", i);
while (temp) {
printf("%d -> ", temp->key);
temp = temp->next;
}
printf("NULL\n");
}
}
int main() {
init();
int keys[] = {23, 43, 13, 27, 88, 52, 19, 20, 55, 60};
return 0;
}
*