Data Structures Lab Assignment 2
Data Structures Lab Assignment 2
struct Node {
int data;
struct Node *left, *right;
};
// Inorder traversal
void inorder(struct Node* root) {
if (root != NULL) {
inorder(root->left);
printf("%d ", root->data);
inorder(root->right);
}
}
int main() {
int values[] = {5, 1, 7, 6, 3, 9, 6, 17, 64, 100, 2, 4};
int n = sizeof(values) / sizeof(values[0]);
return 0;
}
3.Program Statement: Explain how the bubble sort algorithm works for
the list of numbers 11, 35, 67, 26, 121,45,11, 39, 113.
#include <stdio.h>
int main() {
int arr[] = {11, 35, 67, 26, 121, 45, 11, 39, 113};
int n = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, n);
return 0;
}
Output:
4.Program Statement: Write a program to generate n random numbers
and to find the maximum minimum number and their sum.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n, i;
printf("Enter the number of random elements: ");
scanf("%d", &n);
int arr[n];
srand(time(NULL)); // Seed the random number generator
return 0;
}
Output:
int main() {
int arr[] = {53, 81, 23, 28, 65, 43, 52, 95, 22};
int n = sizeof(arr) / sizeof(arr[0]);
quickSort(arr, 0, n - 1);
return 0;
}
Output: