├── .gitattributes ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── Assignment 1 .c ├── DAA ├── .vscode │ ├── settings.json │ └── tasks.json ├── HeapSort.c ├── HeapSort.exe ├── Kruskal.c ├── Kruskal.exe ├── LABS │ ├── Phase1 │ │ ├── program1a.c │ │ ├── program1a.exe │ │ ├── program1b.c │ │ ├── program1b.exe │ │ ├── program2a.c │ │ ├── program2a.exe │ │ ├── program2b.c │ │ ├── program2b.exe │ │ ├── program3a.c │ │ ├── program3a.exe │ │ ├── program4a.c │ │ ├── program4a.exe │ │ ├── program5a.c │ │ ├── program5a.exe │ │ ├── program6a.c │ │ └── program6a.exe │ └── Phase2 │ │ ├── program1a.c │ │ ├── program1a.exe │ │ ├── program1b.c │ │ ├── program1b.exe │ │ ├── program2a.c │ │ ├── program2a.exe │ │ ├── program2b.c │ │ ├── program2b.exe │ │ ├── program3a.c │ │ ├── program3a.exe │ │ ├── program4a.c │ │ └── program4a.exe ├── Strassen.c ├── Strassen.exe ├── mergeSort.c ├── mergeSort.exe ├── mergeSort_beta.c └── mergeSort_beta.exe ├── LICENSE ├── Lab-Practise ├── 1a.c ├── 1a.exe ├── 1b.c ├── 1b.exe ├── 2a.c ├── 2a.exe ├── 2b.c ├── 2b.exe ├── 3a.c ├── 3a.exe ├── 3b.c └── 3b.exe ├── README.md ├── SEE ├── Re-Revision │ ├── .vscode │ │ └── tasks.json │ ├── Queue.c │ ├── Queue.exe │ ├── TowerOfHanoi.c │ ├── bst.c │ ├── bst.exe │ ├── singly.c │ ├── singly.exe │ ├── stack.c │ └── stack.exe ├── basic.c ├── basic.exe ├── doubly.c ├── hanoi.c ├── hanoi.exe ├── queue.c ├── queue.exe ├── singly.c ├── singly.exe ├── sparse.c ├── sparse.exe ├── stack.c ├── stack.exe ├── struct.c └── struct.exe ├── Test.c └── Test.exe /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw64/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "d:/Visual Studio Codes/C Language/DS-Practise", 12 | "program": "d:/Visual Studio Codes/C Language/DS-Practise/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false 59 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc.exe build active file", 6 | "command": "C:\\mingw64\\bin\\gcc.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": ["$gcc"], 18 | "group": "build", 19 | "detail": "Task generated by Debugger." 20 | }, 21 | { 22 | "type": "cppbuild", 23 | "label": "C/C++: g++.exe build active file", 24 | "command": "C:\\msys64\\mingw64\\bin\\g++.exe", 25 | "args": [ 26 | "-fdiagnostics-color=always", 27 | "-g", 28 | "${file}", 29 | "-o", 30 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 31 | ], 32 | "options": { 33 | "cwd": "${fileDirname}" 34 | }, 35 | "problemMatcher": ["$gcc"], 36 | "group": { 37 | "kind": "build", 38 | "isDefault": true 39 | }, 40 | "detail": "compiler: C:\\msys64\\mingw64\\bin\\g++.exe" 41 | }, 42 | { 43 | "type": "cppbuild", 44 | "label": "C/C++: clang.exe build active file", 45 | "command": "C:\\mingw64\\bin\\clang.exe", 46 | "args": [ 47 | "-fcolor-diagnostics", 48 | "-fansi-escape-codes", 49 | "-g", 50 | "${file}", 51 | "-o", 52 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 53 | ], 54 | "options": { 55 | "cwd": "${fileDirname}" 56 | }, 57 | "problemMatcher": ["$gcc"], 58 | "group": "build", 59 | "detail": "compiler: C:\\mingw64\\bin\\clang.exe" 60 | } 61 | ], 62 | "version": "2.0.0" 63 | } 64 | -------------------------------------------------------------------------------- /Assignment 1 .c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | 6 | float m = 20; /*20kg*/ 7 | float v = 5; /*5 m/s*/ 8 | float KE; 9 | KE = 0.5*m*v*v; 10 | 11 | printf("Kinetic Energy (KE) = %f Joules\n", KE); /*print the Kinetic Energy in Joules*/ 12 | 13 | printf("KE = %f",KE); 14 | 15 | } -------------------------------------------------------------------------------- /DAA/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": ["Heapify", "Kruskal", "strassen", "xroot", "yroot"], 3 | "files.associations": { 4 | "stdlib.h": "c" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /DAA/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc.exe build active file", 6 | "command": "C:\\mingw64\\bin\\gcc.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /DAA/HeapSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Function to heapify a subtree rooted at index i 4 | void maxHeapify(int arr[], int n, int i) 5 | { 6 | int largest = i; 7 | int left = 2 * i + 1; 8 | int right = 2 * i + 2; 9 | 10 | // Left child larger than root? 11 | if (left < n && arr[left] > arr[largest]) 12 | largest = left; 13 | 14 | // Right child larger than current largest? 15 | if (right < n && arr[right] > arr[largest]) 16 | largest = right; 17 | 18 | // If largest is not root, swap and heapify again 19 | if (largest != i) 20 | { 21 | int temp = arr[i]; 22 | arr[i] = arr[largest]; 23 | arr[largest] = temp; 24 | 25 | // Recursively heapify the affected subtree 26 | maxHeapify(arr, n, largest); 27 | } 28 | } 29 | 30 | // Main Heap Sort function 31 | void heapSort(int arr[], int n) 32 | { 33 | // Step 1: Build max heap (start from last non-leaf node) 34 | for (int i = n / 2 - 1; i >= 0; i--) 35 | maxHeapify(arr, n, i); 36 | 37 | // Step 2: One by one extract elements from heap 38 | for (int i = n - 1; i > 0; i--) 39 | { 40 | // Swap current root with end element 41 | int temp = arr[0]; 42 | arr[0] = arr[i]; 43 | arr[i] = temp; 44 | 45 | // Heapify the reduced heap 46 | maxHeapify(arr, i, 0); 47 | } 48 | } 49 | 50 | // Helper function to print array 51 | void printArray(int arr[], int n) 52 | { 53 | for (int i = 0; i < n; ++i) 54 | printf("%d ", arr[i]); 55 | printf("\n"); 56 | } 57 | 58 | // Driver code 59 | int main() 60 | { 61 | int arr[] = {4, 10, 3, 5, 1}; 62 | int n = sizeof(arr) / sizeof(arr[0]); 63 | 64 | heapSort(arr, n); 65 | 66 | printf("Sorted array in ascending order:\n"); 67 | printArray(arr, n); 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /DAA/HeapSort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/HeapSort.exe -------------------------------------------------------------------------------- /DAA/Kruskal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Structure to represent an edge 5 | struct Edge 6 | { 7 | int src, dest, weight; 8 | }; 9 | 10 | // Structure to represent a graph 11 | struct Graph 12 | { 13 | int V, E; 14 | struct Edge *edge; 15 | }; 16 | 17 | // Structure to represent a subset for union-find 18 | struct Subset 19 | { 20 | int parent; 21 | int rank; 22 | }; 23 | 24 | // Function to create a graph 25 | struct Graph *createGraph(int V, int E) 26 | { 27 | struct Graph *graph = (struct Graph *)malloc(sizeof(struct Graph)); 28 | graph->V = V; 29 | graph->E = E; 30 | graph->edge = (struct Edge *)malloc(E * sizeof(struct Edge)); 31 | return graph; 32 | } 33 | 34 | // Find set of an element i (uses path compression) 35 | int find(struct Subset subsets[], int i) 36 | { 37 | if (subsets[i].parent != i) 38 | { 39 | // Path compression: directly assign parent to the root 40 | subsets[i].parent = find(subsets, subsets[i].parent); 41 | } 42 | return subsets[i].parent; 43 | } 44 | 45 | // Union of two sets (uses union by rank) 46 | void Union(struct Subset subsets[], int x, int y) 47 | { 48 | int xroot = find(subsets, x); 49 | int yroot = find(subsets, y); 50 | 51 | if (subsets[xroot].rank < subsets[yroot].rank) 52 | subsets[xroot].parent = yroot; 53 | else if (subsets[xroot].rank > subsets[yroot].rank) 54 | subsets[yroot].parent = xroot; 55 | else 56 | { 57 | subsets[yroot].parent = xroot; 58 | subsets[xroot].rank++; 59 | } 60 | } 61 | 62 | // Compare function for qsort 63 | int compareEdges(const void *a, const void *b) 64 | { 65 | struct Edge *e1 = (struct Edge *)a; 66 | struct Edge *e2 = (struct Edge *)b; 67 | return e1->weight - e2->weight; 68 | } 69 | 70 | // Kruskal's algorithm 71 | void KruskalMST(struct Graph *graph) 72 | { 73 | int V = graph->V; 74 | struct Edge result[V]; // Store result MST 75 | int e = 0; // Index for result[] 76 | int i = 0; // Index for sorted edges 77 | 78 | // Step 1: Sort all edges in non-decreasing order of weight 79 | qsort(graph->edge, graph->E, sizeof(graph->edge[0]), compareEdges); 80 | 81 | // Allocate memory for creating subsets 82 | struct Subset *subsets = (struct Subset *)malloc(V * sizeof(struct Subset)); 83 | 84 | // Initialize the subsets (each vertex is its own parent) 85 | for (int v = 0; v < V; ++v) 86 | { 87 | subsets[v].parent = v; 88 | subsets[v].rank = 0; 89 | } 90 | 91 | // Step 2: Number of edges in MST = V - 1 92 | while (e < V - 1 && i < graph->E) 93 | { 94 | struct Edge next_edge = graph->edge[i++]; 95 | 96 | // Find the root of the source and destination vertices 97 | int x = find(subsets, next_edge.src); 98 | int y = find(subsets, next_edge.dest); 99 | 100 | // If including this edge does not cause a cycle, include it in the result 101 | if (x != y) 102 | { 103 | result[e++] = next_edge; 104 | Union(subsets, x, y); 105 | } 106 | } 107 | 108 | // Print the resulting MST 109 | printf("Edges in the Minimum Spanning Tree:\n"); 110 | for (i = 0; i < e; ++i) 111 | printf("%d -- %d == %d\n", result[i].src + 1, result[i].dest + 1, result[i].weight); 112 | } 113 | 114 | // Main function 115 | int main() 116 | { 117 | int V, E; 118 | printf("Enter number of vertices and edges: "); 119 | scanf("%d %d", &V, &E); 120 | 121 | struct Graph *graph = createGraph(V, E); 122 | 123 | printf("Enter edges (src dest weight):\n"); 124 | for (int i = 0; i < E; i++) 125 | { 126 | int u, v, w; 127 | scanf("%d %d %d", &u, &v, &w); 128 | graph->edge[i].src = u - 1; 129 | graph->edge[i].dest = v - 1; 130 | graph->edge[i].weight = w; 131 | } 132 | 133 | KruskalMST(graph); 134 | 135 | return 0; 136 | } 137 | -------------------------------------------------------------------------------- /DAA/Kruskal.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/Kruskal.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program1a.c: -------------------------------------------------------------------------------- 1 | #include 2 | void LSearch(int arr[], int size, int target, int index[]) 3 | { 4 | int count = 0; 5 | for (int i = 0; i < size; i++) 6 | { 7 | if (arr[i] == target) 8 | { 9 | index[count++] = i; 10 | } 11 | } 12 | if (count == 0) 13 | { 14 | printf("Element not found in array\n"); 15 | return; 16 | } 17 | printf("Element %d found at indices: ", target); 18 | for (int i = 0; i < count; i++) 19 | { 20 | printf("%d ", index[i]); 21 | } 22 | } 23 | 24 | int main() 25 | { 26 | int arr[] = {1, 2, 3, 4, 5, 3, 6, 7, 3}; 27 | int size = sizeof(arr) / sizeof(arr[0]); 28 | int target = 3; 29 | int index[size]; 30 | LSearch(arr, size, target, index); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program1a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program1a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program1b.c: -------------------------------------------------------------------------------- 1 | #include 2 | int validate(int arr[], int size) 3 | { 4 | for (int i = 0; i < size - 1; i++) 5 | { 6 | if (arr[i] > arr[i + 1]) 7 | { 8 | return 0; 9 | } 10 | } 11 | 12 | return 1; 13 | } 14 | 15 | int BinarySearch(int arr[], int size, int key) 16 | { 17 | int low = 0, high = size - 1; 18 | while (low < high) 19 | { 20 | int mid = low + (high - low) / 2; 21 | if (key == arr[mid]) 22 | { 23 | return mid; 24 | } 25 | else if (key < arr[mid]) 26 | { 27 | high = mid - 1; 28 | } 29 | else 30 | { 31 | low = mid + 1; 32 | } 33 | } 34 | return -1; 35 | } 36 | 37 | int main() 38 | { 39 | int arr[] = {2, 3, 4, 10, 40}; 40 | int size = sizeof(arr) / sizeof(arr[0]); 41 | int key = 10; 42 | if (validate(arr, size)) 43 | { 44 | int index = BinarySearch(arr, size, key); 45 | if (index == -1) 46 | { 47 | printf("Element not found\n"); 48 | } 49 | else 50 | { 51 | printf("Element found at index %d\n", index); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program1b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program1b.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program2a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void merge(int arr[], int low, int mid, int high) 4 | { 5 | int i = low, j = mid + 1, k = 0; 6 | int *temp = (int *)malloc((high - low + 1) * sizeof(int)); 7 | if (temp == NULL) 8 | { 9 | printf("Memory allocation failed\n"); 10 | return; 11 | } 12 | while (i <= mid && j <= high) 13 | { 14 | if (arr[i] < arr[j]) 15 | { 16 | temp[k++] = arr[i++]; 17 | } 18 | else 19 | { 20 | temp[k++] = arr[j++]; 21 | } 22 | } 23 | while (i <= mid) 24 | { 25 | temp[k++] = arr[i++]; 26 | } 27 | while (j <= high) 28 | { 29 | temp[k++] = arr[j++]; 30 | } 31 | for (int i = low; i <= high; i++) 32 | { 33 | arr[i] = temp[i - low]; 34 | } 35 | free(temp); 36 | } 37 | 38 | void mergeSort(int arr[], int low, int high) 39 | { 40 | if (low < high) 41 | { 42 | int mid = (low + high) / 2; 43 | mergeSort(arr, low, mid); 44 | mergeSort(arr, mid + 1, high); 45 | merge(arr, low, mid, high); 46 | } 47 | } 48 | 49 | int main() 50 | { 51 | int arr[] = {12, 11, 13, 5, 6, 7}; 52 | int n = sizeof(arr) / sizeof(arr[0]); 53 | mergeSort(arr, 0, n - 1); 54 | printf("Sorted array:\n"); 55 | for (int i = 0; i < n; i++) 56 | { 57 | printf("%d ", arr[i]); 58 | } 59 | printf("\n"); 60 | return 0; 61 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program2a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program2a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program2b.c: -------------------------------------------------------------------------------- 1 | #include 2 | void swap(int arr[], int a, int b) 3 | { 4 | int temp = arr[a]; 5 | arr[a] = arr[b]; 6 | arr[b] = temp; 7 | } 8 | 9 | int partition(int arr[], int low, int high) 10 | { 11 | int pivot = arr[high], i = low; 12 | for (int j = low; j < high; j++) 13 | { 14 | if (arr[j] >= pivot) 15 | { 16 | continue; 17 | } 18 | else 19 | { 20 | swap(arr, i, j); 21 | i++; 22 | } 23 | } 24 | swap(arr, i, high); 25 | return i; 26 | } 27 | 28 | void quickSort(int arr[], int low, int high) 29 | { 30 | if (low < high) 31 | { 32 | int pi = partition(arr, low, high); 33 | quickSort(arr, low, pi - 1); 34 | quickSort(arr, pi + 1, high); 35 | } 36 | } 37 | 38 | int main() 39 | { 40 | int arr[] = {10, 7, 8, 9, 1, 5}; 41 | int n = sizeof(arr) / sizeof(arr[0]); 42 | quickSort(arr, 0, n - 1); 43 | printf("Sorted array in ascending order: "); 44 | for (int i = 0; i < n; i++) 45 | printf("%d ", arr[i]); 46 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program2b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program2b.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program3a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void initializeGraph(int adj[100][100], int vertices) 5 | { 6 | for (int i = 0; i < vertices; i++) 7 | { 8 | for (int j = 0; j < vertices; j++) 9 | { 10 | adj[i][j] = 0; 11 | } 12 | } 13 | } 14 | 15 | void addEdge(int adj[100][100], int start, int edge) 16 | { 17 | adj[start][edge] = 1; 18 | adj[edge][start] = 1; 19 | } 20 | 21 | void DFS(int adj[100][100], int vertices, int vertex, bool visited[]) 22 | { 23 | visited[vertex] = true; 24 | for (int i = 0; i < vertices; i++) 25 | { 26 | if (adj[vertex][i] && !visited[i]) 27 | { 28 | DFS(adj, vertices, i, visited); 29 | } 30 | } 31 | } 32 | 33 | bool isConnected(int adj[100][100], int vertices) 34 | { 35 | bool visited[100] = {false}; 36 | DFS(adj, vertices, 0, visited); 37 | for (int i = 0; i < vertices; i++) 38 | { 39 | if (!visited[i]) 40 | { 41 | return false; 42 | } 43 | } 44 | return true; 45 | } 46 | 47 | int main() 48 | { 49 | int adj[100][100]; 50 | int vertices, edges; 51 | printf("Enter the number of vertices: "); 52 | scanf("%d", &vertices); 53 | 54 | initializeGraph(adj, vertices); 55 | 56 | printf("Enter the number of edges: "); 57 | scanf("%d", &edges); 58 | printf("Enter the edges (start end):\n"); 59 | for (int i = 0; i < edges; i++) 60 | { 61 | int start, end; 62 | scanf("%d %d", &start, &end); 63 | addEdge(adj, start, end); 64 | } 65 | 66 | bool connected = isConnected(adj, vertices); 67 | if (connected) 68 | { 69 | printf("The graph is connected.\n"); 70 | } 71 | else 72 | { 73 | printf("The graph is not connected.\n"); 74 | } 75 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program3a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program3a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program4a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX 100 4 | 5 | int queue[MAX]; 6 | int front = -1, rear = -1; 7 | 8 | void enqueue(int data) 9 | { 10 | if (rear == MAX - 1) 11 | { 12 | printf("Queue Overflow\n"); 13 | return; 14 | } 15 | if (front = -1) 16 | { 17 | front = 0; 18 | } 19 | queue[++rear] = data; 20 | } 21 | 22 | int dequeue() 23 | { 24 | if (front == -1 || front > rear) 25 | { 26 | printf("Queue Underflow\n"); 27 | return -1; 28 | } 29 | return queue[front++]; 30 | } 31 | 32 | int isEmpty() 33 | { 34 | return ((front == -1) || (front > rear)); 35 | } 36 | 37 | void BFS(int graph[MAX][MAX], int vertices, int start, int visited[]) 38 | { 39 | visited[start] = 1; 40 | enqueue(start); 41 | 42 | while (!isEmpty()) 43 | { 44 | int current = dequeue(); 45 | printf("%d ", current); 46 | 47 | for (int i = 0; i < vertices; i++) 48 | { 49 | if (graph[current][i] == 1 && !visited[i]) 50 | { 51 | visited[i] = 1; 52 | enqueue(i); 53 | } 54 | } 55 | } 56 | } 57 | 58 | int main() 59 | { 60 | int vertices, graph[MAX][MAX], visited[MAX]; 61 | 62 | printf("Enter the number of vertices: "); 63 | scanf("%d", &vertices); 64 | 65 | for (int i = 0; i < vertices; i++) 66 | { 67 | for (int j = 0; j < vertices; j++) 68 | { 69 | scanf("%d", &graph[i][j]); 70 | } 71 | } 72 | 73 | int start; 74 | printf("Enter the starting vertex: "); 75 | scanf("%d", &start); 76 | 77 | for (int i = 0; i < vertices; i++) 78 | { 79 | visited[i] = 0; 80 | } 81 | 82 | printf("Breadth First Search (BFS) traversal from vertex %d:\n", start); 83 | BFS(graph, vertices, start, visited); 84 | 85 | return 0; 86 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program4a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program4a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program5a.c: -------------------------------------------------------------------------------- 1 | #include 2 | void warshall(int arr[100][100], int n) 3 | { 4 | for (int k = 0; k < n; k++) 5 | { 6 | for (int i = 0; i < n; i++) 7 | { 8 | for (int j = 0; j < n; j++) 9 | { 10 | if (arr[i][k] && arr[k][j]) 11 | arr[i][j] = 1; 12 | } 13 | } 14 | } 15 | printf("\nThe transitive closure of the given graph is:\n"); 16 | for (int i = 0; i < n; i++) 17 | { 18 | for (int j = 0; j < n; j++) 19 | { 20 | printf("%d ", arr[i][j]); 21 | } 22 | printf("\n"); 23 | } 24 | } 25 | 26 | int main() 27 | { 28 | int n; 29 | printf("Enter the number of vertices: "); 30 | scanf("%d", &n); 31 | int adj[100][100]; 32 | printf("Enter the adjacency matrix of the graph (1 for edge, 0 for no edge):\n"); 33 | for (int i = 0; i < n; i++) 34 | { 35 | for (int j = 0; j < n; j++) 36 | { 37 | scanf("%d", &adj[i][j]); 38 | } 39 | } 40 | warshall(adj, n); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program5a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program5a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program6a.c: -------------------------------------------------------------------------------- 1 | #include 2 | void floyd(int arr[100][100], int n) 3 | { 4 | for (int k = 0; k < n; k++) 5 | { 6 | for (int i = 0; i < n; i++) 7 | { 8 | for (int j = 0; j < n; j++) 9 | { 10 | if ((arr[i][k] + arr[k][j]) < arr[i][j]) 11 | { 12 | arr[i][j] = arr[i][k] + arr[k][j]; 13 | } 14 | } 15 | } 16 | } 17 | 18 | printf("The shortest distances between all pairs of vertices are:\n"); 19 | for (int i = 0; i < n; i++) 20 | { 21 | for (int j = 0; j < n; j++) 22 | { 23 | if (arr[i][j] > 100) 24 | { 25 | printf("%7s", "INF"); 26 | } 27 | else 28 | { 29 | printf("%7d", arr[i][j]); 30 | } 31 | } 32 | printf("\n"); 33 | } 34 | } 35 | 36 | int main() 37 | { 38 | int n; 39 | printf("Enter the number of vertices: "); 40 | scanf("%d", &n); 41 | int adj[100][100]; 42 | printf("Enter the adjacency matrix of the graph (use 100 for no edge):\n"); 43 | for (int i = 0; i < n; i++) 44 | { 45 | for (int j = 0; j < n; j++) 46 | { 47 | scanf("%d", &adj[i][j]); 48 | } 49 | } 50 | floyd(adj, n); 51 | return 0; 52 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase1/program6a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase1/program6a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program1a.c: -------------------------------------------------------------------------------- 1 | #include 2 | void linearSearch(int arr[], int n, int key, int indices[]) 3 | { 4 | int count = 0; 5 | for (int i = 0; i < n; i++) 6 | { 7 | if (arr[i] == key) 8 | { 9 | indices[count++] = i; 10 | } 11 | } 12 | if (count == 0) 13 | { 14 | printf("Element not found in array\n"); 15 | return; 16 | } 17 | printf("Element found at indices: "); 18 | for (int i = 0; i < count; i++) 19 | { 20 | printf("%d ", indices[i]); 21 | } 22 | } 23 | 24 | int main() 25 | { 26 | int arr[] = {10, 22, 8, 29, 30, 29, 41, 50}; 27 | int n = sizeof(arr) / sizeof(arr[0]); 28 | int key = 29; 29 | int indices[n]; 30 | linearSearch(arr, n, key, indices); 31 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program1a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase2/program1a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program1b.c: -------------------------------------------------------------------------------- 1 | #include 2 | int BinarySearch(int arr[], int n, int key) 3 | { 4 | int low = 0; 5 | int high = n - 1; 6 | while (low < high) 7 | { 8 | int mid = (low + high) / 2; 9 | if (arr[mid] == key) 10 | { 11 | return low; 12 | } 13 | else if (key < arr[mid]) 14 | { 15 | high = mid - 1; 16 | } 17 | else 18 | { 19 | low = mid + 1; 20 | } 21 | } 22 | return -1; 23 | } 24 | 25 | int main() 26 | { 27 | int arr[] = {2, 3, 4, 10, 40}; 28 | int n = sizeof(arr) / sizeof(arr[0]); 29 | int key = 10; 30 | int result = BinarySearch(arr, n, key); 31 | (result == -1) ? printf("Element is not present in array") : printf("Element found at index %d", result); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program1b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase2/program1b.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program2a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void merge(int arr[], int low, int mid, int high) 4 | { 5 | int i = low, j = mid + 1, k = 0; 6 | int size = high - low + 1; 7 | int *temp = (int *)malloc(size * sizeof(int)); 8 | if (temp == NULL) 9 | { 10 | printf("Memory allocation failed\n"); 11 | return; 12 | } 13 | while (i <= mid && j <= high) 14 | { 15 | if (arr[i] < arr[j]) 16 | { 17 | temp[k++] = arr[i++]; 18 | } 19 | else 20 | { 21 | temp[k++] = arr[j++]; 22 | } 23 | } 24 | while (i <= mid) 25 | { 26 | temp[k++] = arr[i++]; 27 | } 28 | while (j <= high) 29 | { 30 | temp[k++] = arr[j++]; 31 | } 32 | for (int i = low; i <= high; i++) 33 | { 34 | arr[i] = temp[i - low]; 35 | } 36 | free(temp); 37 | } 38 | 39 | void mergeSort(int arr[], int low, int high) 40 | { 41 | if (low < high) 42 | { 43 | int mid = (low + high) / 2; 44 | mergeSort(arr, low, mid); 45 | mergeSort(arr, mid + 1, high); 46 | merge(arr, low, mid, high); 47 | } 48 | } 49 | 50 | int main() 51 | { 52 | int arr[] = {12, 11, 13, 5, 6, 7}; 53 | int n = sizeof(arr) / sizeof(arr[0]); 54 | mergeSort(arr, 0, n - 1); 55 | printf("Sorted array:\n"); 56 | for (int i = 0; i < n; i++) 57 | { 58 | printf("%d ", arr[i]); 59 | } 60 | printf("\n"); 61 | return 0; 62 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program2a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase2/program2a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program2b.c: -------------------------------------------------------------------------------- 1 | #include 2 | void swap(int arr[], int a, int b) 3 | { 4 | int temp = arr[a]; 5 | arr[a] = arr[b]; 6 | arr[b] = temp; 7 | } 8 | 9 | int partition(int arr[], int low, int high) 10 | { 11 | int pivot = arr[high], i = low; 12 | for (int j = low; j < high; j++) 13 | { 14 | if (arr[j] >= pivot) 15 | { 16 | continue; 17 | } 18 | else 19 | { 20 | swap(arr, i, j); 21 | i++; 22 | } 23 | } 24 | swap(arr, i, high); 25 | return i; 26 | } 27 | 28 | void quickSort(int arr[], int low, int high) 29 | { 30 | if (low < high) 31 | { 32 | int pi = partition(arr, low, high); 33 | quickSort(arr, low, pi - 1); 34 | quickSort(arr, pi + 1, high); 35 | } 36 | } 37 | 38 | int main() 39 | { 40 | int arr[] = {10, 7, 8, 9, 1, 5}; 41 | int n = sizeof(arr) / sizeof(arr[0]); 42 | quickSort(arr, 0, n - 1); 43 | printf("Sorted array: "); 44 | for (int i = 0; i < n; i++) 45 | printf("%d ", arr[i]); 46 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program2b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase2/program2b.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program3a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void initializeGraph(int adj[100][100], int vertices) 5 | { 6 | for (int i = 0; i < vertices; i++) 7 | { 8 | for (int j = 0; j < vertices; j++) 9 | { 10 | adj[i][j] = 0; 11 | } 12 | } 13 | } 14 | 15 | void addEdge(int adj[100][100], int start, int end) 16 | { 17 | adj[start][end] = 1; 18 | adj[end][start] = 1; 19 | } 20 | 21 | void DFS(int adj[100][100], int vertices, int vertex, bool visited[]) 22 | { 23 | visited[vertex] = true; 24 | for (int i = 0; i < vertices; i++) 25 | { 26 | if (adj[vertex][i] && !visited[i]) 27 | { 28 | DFS(adj, vertices, i, visited); 29 | } 30 | } 31 | } 32 | 33 | bool isConnected(int adj[100][100], int vertices) 34 | { 35 | bool visited[100] = {false}; 36 | DFS(adj, vertices, 0, visited); 37 | for (int i = 0; i < vertices; i++) 38 | { 39 | if (!visited[i]) 40 | { 41 | return false; 42 | } 43 | } 44 | return true; 45 | } 46 | 47 | int main() 48 | { 49 | int vertices, edges; 50 | printf("Enter the number of vertices and edges: "); 51 | scanf("%d %d", &vertices, &edges); 52 | 53 | int adj[100][100]; 54 | initializeGraph(adj, vertices); 55 | 56 | printf("Enter the edges (start end):\n"); 57 | for (int i = 0; i < edges; i++) 58 | { 59 | int start, end; 60 | scanf("%d %d", &start, &end); 61 | addEdge(adj, start, end); 62 | } 63 | 64 | if (isConnected(adj, vertices)) 65 | { 66 | printf("The graph is connected.\n"); 67 | } 68 | else 69 | { 70 | printf("The graph is not connected.\n"); 71 | } 72 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program3a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase2/program3a.exe -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program4a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX 100 4 | 5 | int queue[MAX]; 6 | int front = -1, rear = -1; 7 | 8 | void enqueue(int data) 9 | { 10 | if (rear == MAX - 1) 11 | { 12 | printf("Queue Overflow\n"); 13 | return; 14 | } 15 | if (front == -1) 16 | { 17 | front = 0; 18 | } 19 | queue[++rear] = data; 20 | } 21 | 22 | int dequeue() 23 | { 24 | if (front == -1 || front > rear) 25 | { 26 | printf("Queue Underflow\n"); 27 | return -1; 28 | } 29 | return queue[front++]; 30 | } 31 | 32 | int isEmpty() 33 | { 34 | return front == -1 || front > rear; 35 | } 36 | 37 | void BFS(int graph[MAX][MAX], int vertices, int start, int visited[]) 38 | { 39 | visited[start] = 1; 40 | enqueue(start); 41 | 42 | while (!isEmpty()) 43 | { 44 | int current = dequeue(); 45 | printf("%d ", current); 46 | 47 | for (int i = 0; i < vertices; i++) 48 | { 49 | if (graph[current][i] == 1 && !visited[i]) 50 | { 51 | visited[i] = 1; 52 | enqueue(i); 53 | } 54 | } 55 | } 56 | } 57 | 58 | int main() 59 | { 60 | int vertices, graph[MAX][MAX], visited[MAX]; 61 | 62 | printf("Enter the number of vertices: "); 63 | scanf("%d", &vertices); 64 | 65 | printf("Enter the adjacency matrix:\n"); 66 | for (int i = 0; i < vertices; i++) 67 | { 68 | for (int j = 0; j < vertices; j++) 69 | { 70 | scanf("%d", &graph[i][j]); 71 | } 72 | } 73 | 74 | printf("Enter the starting vertex: "); 75 | int start; 76 | scanf("%d", &start); 77 | 78 | for (int i = 0; i < vertices; i++) 79 | { 80 | visited[i] = 0; 81 | } 82 | 83 | printf("Breadth First Search (BFS) traversal from vertex %d:\n", start); 84 | BFS(graph, vertices, start, visited); 85 | 86 | return 0; 87 | } -------------------------------------------------------------------------------- /DAA/LABS/Phase2/program4a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/LABS/Phase2/program4a.exe -------------------------------------------------------------------------------- /DAA/Strassen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void add(int **A, int **B, int **C, int size) 5 | { 6 | for (int i = 0; i < size; i++) 7 | for (int j = 0; j < size; j++) 8 | C[i][j] = A[i][j] + B[i][j]; 9 | } 10 | 11 | void subtract(int **A, int **B, int **C, int size) 12 | { 13 | for (int i = 0; i < size; i++) 14 | for (int j = 0; j < size; j++) 15 | C[i][j] = A[i][j] - B[i][j]; 16 | } 17 | 18 | int **allocateMatrix(int size) 19 | { 20 | int **matrix = malloc(size * sizeof(int *)); 21 | for (int i = 0; i < size; i++) 22 | matrix[i] = calloc(size, sizeof(int)); 23 | return matrix; 24 | } 25 | 26 | void freeMatrix(int **matrix, int size) 27 | { 28 | for (int i = 0; i < size; i++) 29 | free(matrix[i]); 30 | free(matrix); 31 | } 32 | 33 | void strassen(int **A, int **B, int **C, int size) 34 | { 35 | if (size == 1) 36 | { 37 | C[0][0] = A[0][0] * B[0][0]; 38 | return; 39 | } 40 | 41 | int newSize = size / 2; 42 | int **A11 = allocateMatrix(newSize), **A12 = allocateMatrix(newSize); 43 | int **A21 = allocateMatrix(newSize), **A22 = allocateMatrix(newSize); 44 | int **B11 = allocateMatrix(newSize), **B12 = allocateMatrix(newSize); 45 | int **B21 = allocateMatrix(newSize), **B22 = allocateMatrix(newSize); 46 | int **C11 = allocateMatrix(newSize), **C12 = allocateMatrix(newSize); 47 | int **C21 = allocateMatrix(newSize), **C22 = allocateMatrix(newSize); 48 | int **M1 = allocateMatrix(newSize), **M2 = allocateMatrix(newSize); 49 | int **M3 = allocateMatrix(newSize), **M4 = allocateMatrix(newSize); 50 | int **M5 = allocateMatrix(newSize), **M6 = allocateMatrix(newSize); 51 | int **M7 = allocateMatrix(newSize); 52 | int **temp1 = allocateMatrix(newSize), **temp2 = allocateMatrix(newSize); 53 | 54 | // Split matrices 55 | for (int i = 0; i < newSize; i++) 56 | { 57 | for (int j = 0; j < newSize; j++) 58 | { 59 | A11[i][j] = A[i][j]; 60 | A12[i][j] = A[i][j + newSize]; 61 | A21[i][j] = A[i + newSize][j]; 62 | A22[i][j] = A[i + newSize][j + newSize]; 63 | 64 | B11[i][j] = B[i][j]; 65 | B12[i][j] = B[i][j + newSize]; 66 | B21[i][j] = B[i + newSize][j]; 67 | B22[i][j] = B[i + newSize][j + newSize]; 68 | } 69 | } 70 | 71 | // M1 = (A11 + A22)(B11 + B22) 72 | add(A11, A22, temp1, newSize); 73 | add(B11, B22, temp2, newSize); 74 | strassen(temp1, temp2, M1, newSize); 75 | 76 | // M2 = (A21 + A22)B11 77 | add(A21, A22, temp1, newSize); 78 | strassen(temp1, B11, M2, newSize); 79 | 80 | // M3 = A11(B12 - B22) 81 | subtract(B12, B22, temp1, newSize); 82 | strassen(A11, temp1, M3, newSize); 83 | 84 | // M4 = A22(B21 - B11) 85 | subtract(B21, B11, temp1, newSize); 86 | strassen(A22, temp1, M4, newSize); 87 | 88 | // M5 = (A11 + A12)B22 89 | add(A11, A12, temp1, newSize); 90 | strassen(temp1, B22, M5, newSize); 91 | 92 | // M6 = (A21 - A11)(B11 + B12) 93 | subtract(A21, A11, temp1, newSize); 94 | add(B11, B12, temp2, newSize); 95 | strassen(temp1, temp2, M6, newSize); 96 | 97 | // M7 = (A12 - A22)(B21 + B22) 98 | subtract(A12, A22, temp1, newSize); 99 | add(B21, B22, temp2, newSize); 100 | strassen(temp1, temp2, M7, newSize); 101 | 102 | // C11 = M1 + M4 - M5 + M7 103 | add(M1, M4, temp1, newSize); 104 | subtract(temp1, M5, temp2, newSize); 105 | add(temp2, M7, C11, newSize); 106 | 107 | // C12 = M3 + M5 108 | add(M3, M5, C12, newSize); 109 | 110 | // C21 = M2 + M4 111 | add(M2, M4, C21, newSize); 112 | 113 | // C22 = M1 - M2 + M3 + M6 114 | subtract(M1, M2, temp1, newSize); 115 | add(temp1, M3, temp2, newSize); 116 | add(temp2, M6, C22, newSize); 117 | 118 | // Combine results into C 119 | for (int i = 0; i < newSize; i++) 120 | { 121 | for (int j = 0; j < newSize; j++) 122 | { 123 | C[i][j] = C11[i][j]; 124 | C[i][j + newSize] = C12[i][j]; 125 | C[i + newSize][j] = C21[i][j]; 126 | C[i + newSize][j + newSize] = C22[i][j]; 127 | } 128 | } 129 | 130 | // Free all allocated memory 131 | freeMatrix(A11, newSize); 132 | freeMatrix(A12, newSize); 133 | freeMatrix(A21, newSize); 134 | freeMatrix(A22, newSize); 135 | freeMatrix(B11, newSize); 136 | freeMatrix(B12, newSize); 137 | freeMatrix(B21, newSize); 138 | freeMatrix(B22, newSize); 139 | freeMatrix(C11, newSize); 140 | freeMatrix(C12, newSize); 141 | freeMatrix(C21, newSize); 142 | freeMatrix(C22, newSize); 143 | freeMatrix(M1, newSize); 144 | freeMatrix(M2, newSize); 145 | freeMatrix(M3, newSize); 146 | freeMatrix(M4, newSize); 147 | freeMatrix(M5, newSize); 148 | freeMatrix(M6, newSize); 149 | freeMatrix(M7, newSize); 150 | freeMatrix(temp1, newSize); 151 | freeMatrix(temp2, newSize); 152 | } 153 | 154 | void printMatrix(int **M, int size) 155 | { 156 | for (int i = 0; i < size; i++) 157 | { 158 | for (int j = 0; j < size; j++) 159 | printf("%4d ", M[i][j]); 160 | printf("\n"); 161 | } 162 | } 163 | 164 | int main() 165 | { 166 | int n; 167 | printf("Enter matrix size (must be a power of 2): "); 168 | scanf("%d", &n); 169 | 170 | // Allocate memory for matrices 171 | int **A = allocateMatrix(n); 172 | int **B = allocateMatrix(n); 173 | int **C = allocateMatrix(n); // Result matrix 174 | 175 | // Input A 176 | printf("Enter elements of matrix A (%d x %d):\n", n, n); 177 | for (int i = 0; i < n; i++) 178 | for (int j = 0; j < n; j++) 179 | scanf("%d", &A[i][j]); 180 | 181 | // Input B 182 | printf("Enter elements of matrix B (%d x %d):\n", n, n); 183 | for (int i = 0; i < n; i++) 184 | for (int j = 0; j < n; j++) 185 | scanf("%d", &B[i][j]); 186 | 187 | // Multiply using Strassen 188 | strassen(A, B, C, n); 189 | 190 | // Output Result 191 | printf("Result matrix C = A * B:\n"); 192 | for (int i = 0; i < n; i++) 193 | { 194 | for (int j = 0; j < n; j++) 195 | printf("%d ", C[i][j]); 196 | printf("\n"); 197 | } 198 | 199 | // Free memory 200 | freeMatrix(A, n); 201 | freeMatrix(B, n); 202 | freeMatrix(C, n); 203 | 204 | return 0; 205 | } 206 | -------------------------------------------------------------------------------- /DAA/Strassen.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/Strassen.exe -------------------------------------------------------------------------------- /DAA/mergeSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void merge(int arr[], int low, int mid, int high) 5 | { 6 | int i = low, j = mid + 1, k = 0; 7 | int *temp = (int *)malloc((high - low + 1) * sizeof(int)); 8 | 9 | if (temp == NULL) 10 | { 11 | printf("Memory allocation failed\n"); 12 | return; 13 | } 14 | 15 | while (i <= mid && j <= high) 16 | { 17 | if (arr[i] <= arr[j]) 18 | { 19 | temp[k++] = arr[i++]; 20 | } 21 | else 22 | { 23 | temp[k++] = arr[j++]; 24 | } 25 | } 26 | 27 | while (i <= mid) 28 | { 29 | temp[k++] = arr[i++]; 30 | } 31 | while (j <= high) 32 | { 33 | temp[k++] = arr[j++]; 34 | } 35 | 36 | for (int itr = low; itr <= high; itr++) 37 | { 38 | arr[itr] = temp[itr - low]; 39 | } 40 | 41 | free(temp); 42 | } 43 | 44 | void mergeSort(int arr[], int low, int high) 45 | { 46 | if (low < high) 47 | { 48 | int mid = (low + high) / 2; 49 | mergeSort(arr, low, mid); 50 | mergeSort(arr, mid + 1, high); 51 | merge(arr, low, mid, high); 52 | } 53 | } 54 | 55 | int main() 56 | { 57 | int n; 58 | printf("Enter the size of the array:"); 59 | scanf("%d", &n); 60 | int arr[n]; 61 | if (n <= 0) 62 | { 63 | printf("Array size must be positive!\n"); 64 | return 1; 65 | } 66 | for (int i = 0; i < n; i++) 67 | { 68 | printf("Enter element number %d:", i + 1); 69 | scanf("%d", &arr[i]); 70 | } 71 | 72 | printf("Original array: "); 73 | for (int i = 0; i < n; i++) 74 | { 75 | printf("%d ", arr[i]); 76 | } 77 | printf("\n"); 78 | 79 | mergeSort(arr, 0, n - 1); 80 | 81 | printf("Sorted array: "); 82 | for (int i = 0; i < n; i++) 83 | { 84 | printf("%d ", arr[i]); 85 | } 86 | printf("\n"); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /DAA/mergeSort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/mergeSort.exe -------------------------------------------------------------------------------- /DAA/mergeSort_beta.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void merge(int arr[], int low, int mid, int high) 4 | { 5 | int i = low; 6 | int j = mid + 1; 7 | int k = low; 8 | int temp[high]; 9 | while (i <= mid && j <= high) 10 | { 11 | if (arr[i] < arr[j]) 12 | { 13 | temp[k++] = arr[i++]; 14 | } 15 | else 16 | { 17 | temp[k++] = arr[j++]; 18 | } 19 | } 20 | 21 | while (i <= mid) 22 | { 23 | temp[k++] = arr[i++]; 24 | } 25 | while (j <= high) 26 | { 27 | temp[k++] = arr[j++]; 28 | } 29 | 30 | for (int itr = low; itr <= high; itr++) 31 | { 32 | arr[itr] = temp[itr]; 33 | } 34 | } 35 | 36 | void mergeSort(int arr[], int low, int high) 37 | { 38 | if (low < high) 39 | { 40 | int mid = (low + high) / 2; 41 | 42 | mergeSort(arr, low, mid); 43 | mergeSort(arr, mid + 1, high); 44 | 45 | merge(arr, low, mid, high); 46 | } 47 | } 48 | 49 | int main() 50 | { 51 | int n; 52 | printf("Enter the size of the array:"); 53 | scanf("%d", &n); 54 | int arr[n]; 55 | if (n <= 0) 56 | { 57 | printf("Array size must be positive!\n"); 58 | return 1; 59 | } 60 | for (int i = 0; i < n; i++) 61 | { 62 | printf("Enter element for index %d:", i); 63 | scanf("%d", &arr[i]); 64 | } 65 | 66 | printf("Original array: "); 67 | for (int i = 0; i < n; i++) 68 | { 69 | printf("%d ", arr[i]); 70 | } 71 | printf("\n"); 72 | 73 | mergeSort(arr, 0, n - 1); 74 | 75 | printf("Sorted array: "); 76 | for (int i = 0; i < n; i++) 77 | { 78 | printf("%d ", arr[i]); 79 | } 80 | printf("\n"); 81 | 82 | return 0; 83 | } -------------------------------------------------------------------------------- /DAA/mergeSort_beta.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/DAA/mergeSort_beta.exe -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Eswar Arji 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lab-Practise/1a.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | 6 | printf("Enter the size of the array: "); 7 | scanf("%d", &n); 8 | int arr[n]; 9 | 10 | printf("Enter the %d elements of the array: \n", n); 11 | for (int i = 0; i < n; i++) 12 | { 13 | printf("Enter element %d: ", i + 1); 14 | scanf("%d", &arr[i]); 15 | } 16 | printf("The elements in the array are: "); 17 | for (int i = 0; i < n; i++) 18 | { 19 | printf("%d ", arr[i]); 20 | } 21 | } -------------------------------------------------------------------------------- /Lab-Practise/1a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/Lab-Practise/1a.exe -------------------------------------------------------------------------------- /Lab-Practise/1b.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | bool verifyRegistration(char registration[]) 6 | { 7 | if (strlen(registration) != 10) 8 | { 9 | return false; 10 | } 11 | for (int i = 0; i < 2; i++) 12 | { 13 | if (!isalpha(registration[i])) 14 | { 15 | return false; 16 | } 17 | } 18 | for (int i = 2; i < 4; i++) 19 | { 20 | if (!isdigit(registration[i])) 21 | { 22 | return false; 23 | } 24 | } 25 | for (int i = 4; i < 6; i++) 26 | { 27 | if (!isalpha(registration[i])) 28 | { 29 | return false; 30 | } 31 | } 32 | for (int i = 6; i < 10; i++) 33 | { 34 | if (!isdigit(registration[i])) 35 | { 36 | return false; 37 | } 38 | } 39 | return true; 40 | } 41 | 42 | int main() 43 | { 44 | char registration[10]; 45 | printf("Enter a 10-digit registration number: "); 46 | scanf("%s", registration); 47 | if (verifyRegistration(registration)) 48 | { 49 | printf("Valid registration number\n"); 50 | } 51 | else 52 | { 53 | printf("Invalid registration number\n"); 54 | } 55 | return 0; 56 | } -------------------------------------------------------------------------------- /Lab-Practise/1b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/Lab-Practise/1b.exe -------------------------------------------------------------------------------- /Lab-Practise/2a.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int m, n, p, q; 5 | printf("Enter the number of rows and columns for the first matrix: "); 6 | scanf("%d%d", &m, &n); 7 | printf("Enter the number of rows and columns for the second matrix: "); 8 | scanf("%d%d", &p, &q); 9 | if (n != p) 10 | { 11 | printf("The matrices cannot be multiplied.\n"); 12 | return 0; 13 | } 14 | int firstMatrix[m][n], secondMatrix[p][q], result[m][q]; 15 | printf("Enter the elements of the first matrix:\n"); 16 | for (int i = 0; i < m; i++) 17 | { 18 | for (int j = 0; j < n; j++) 19 | { 20 | scanf("%d", &firstMatrix[i][j]); 21 | } 22 | } 23 | printf("Enter the elements of the second matrix:\n"); 24 | for (int i = 0; i < p; i++) 25 | { 26 | for (int j = 0; j < q; j++) 27 | { 28 | scanf("%d", &secondMatrix[i][j]); 29 | } 30 | } 31 | for (int i = 0; i < m; i++) 32 | { 33 | for (int j = 0; j < q; j++) 34 | { 35 | result[i][j] = 0; 36 | for (int k = 0; k < n; k++) 37 | { 38 | result[i][j] += firstMatrix[i][k] * secondMatrix[k][j]; 39 | } 40 | } 41 | } 42 | printf("Resultant matrix:\n"); 43 | for (int i = 0; i < m; i++) 44 | { 45 | for (int j = 0; j < q; j++) 46 | { 47 | printf("%d ", result[i][j]); 48 | } 49 | printf("\n"); 50 | } 51 | return 0; 52 | } -------------------------------------------------------------------------------- /Lab-Practise/2a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/Lab-Practise/2a.exe -------------------------------------------------------------------------------- /Lab-Practise/2b.c: -------------------------------------------------------------------------------- 1 | #include 2 | int isValidSudoku(int board[9][9]) 3 | { 4 | for (int i = 0; i < 9; i++) 5 | { 6 | int rows[10] = {0}; 7 | for (int j = 0; j < 9; j++) 8 | { 9 | int temp = board[i][j]; 10 | if (board[i][j] != 0 && rows[temp] == 1) 11 | { 12 | return 0; 13 | } 14 | rows[temp] = 1; 15 | } 16 | } 17 | for (int j = 0; j < 0; j++) 18 | { 19 | int cols[10] = {0}; 20 | for (int i = 0; i < 9; i++) 21 | { 22 | int temp = board[i][j]; 23 | if (board[i][j] != 0 && cols[temp] == 1) 24 | { 25 | return 0; 26 | } 27 | cols[temp] = 1; 28 | } 29 | } 30 | for (int block = 0; block < 9; block++) 31 | { 32 | int subgrid[10] = {0}; 33 | for (int i = block / 3 * 3; i < block / 3 * 3 + 3; i++) 34 | { 35 | for (int j = block % 3 * 3; j < block % 3 * 3 + 3; j++) 36 | { 37 | int temp = board[i][j]; 38 | if (board[i][j] != 0 && subgrid[temp] == 1) 39 | { 40 | return 0; 41 | } 42 | subgrid[temp] = 1; 43 | } 44 | } 45 | } 46 | return 1; 47 | } 48 | 49 | int main() 50 | { 51 | int sudoku[9][9] = { 52 | {5, 3, 0, 0, 7, 0, 0, 0, 0}, 53 | {6, 0, 0, 1, 9, 5, 0, 0, 0}, 54 | {0, 9, 8, 0, 0, 0, 0, 6, 0}, 55 | {8, 0, 0, 0, 6, 0, 0, 0, 3}, 56 | {4, 0, 0, 8, 0, 3, 0, 0, 1}, 57 | {7, 0, 0, 0, 2, 0, 0, 0, 6}, 58 | {0, 6, 0, 0, 0, 0, 2, 8, 0}, 59 | {0, 0, 0, 4, 1, 9, 0, 0, 5}, 60 | {0, 0, 0, 0, 8, 0, 0, 7, 9}}; 61 | if (isValidSudoku(sudoku)) 62 | { 63 | printf("Valid Sudoku\n"); 64 | } 65 | else 66 | { 67 | printf("Invalid Sudoku\n"); 68 | } 69 | return 0; 70 | } -------------------------------------------------------------------------------- /Lab-Practise/2b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/Lab-Practise/2b.exe -------------------------------------------------------------------------------- /Lab-Practise/3a.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct Student 3 | { 4 | int studentId; 5 | char name[50]; 6 | char grade; 7 | float marks[5]; 8 | float averageMarks; 9 | }; 10 | 11 | void calculateAverage(struct Student *student) 12 | { 13 | float totalMarks = 0.0; 14 | for (int i = 0; i < 5; i++) 15 | { 16 | totalMarks += student->marks[i]; 17 | } 18 | student->averageMarks = totalMarks / 5; 19 | } 20 | 21 | void assignGrages(struct Student *student) 22 | { 23 | if (student->averageMarks >= 90) 24 | { 25 | student->grade = 'A'; 26 | } 27 | else if (student->averageMarks >= 80) 28 | { 29 | student->grade = 'B'; 30 | } 31 | else if (student->averageMarks >= 70) 32 | { 33 | student->grade = 'C'; 34 | } 35 | else if (student->averageMarks >= 60) 36 | { 37 | student->grade = 'D'; 38 | } 39 | else 40 | { 41 | student->grade = 'F'; 42 | } 43 | } 44 | 45 | int main() 46 | { 47 | struct Student students[5]; 48 | for (int i = 0; i < 5; i++) 49 | { 50 | printf("Enter student %d details\n", i + 1); 51 | printf("Enter student id: "); 52 | scanf("%d", &students[i].studentId); 53 | printf("Enter student name: "); 54 | scanf("%s", students[i].name); 55 | for (int j = 0; j < 5; j++) 56 | { 57 | printf("Enter marks for subject %d: ", j + 1); 58 | scanf("%f", &students[i].marks[j]); 59 | } 60 | calculateAverage(&students[i]); 61 | assignGrages(&students[i]); 62 | } 63 | 64 | printf("\nStudent Details:\n"); 65 | for (int i = 0; i < 5; i++) 66 | { 67 | printf("Student %d\n", i + 1); 68 | printf("Student ID: %d\n", students[i].studentId); 69 | printf("Student Name: %s\n", students[i].name); 70 | printf("Average Marks: %.2f\n", students[i].averageMarks); 71 | printf("Grade: %c\n", students[i].grade); 72 | printf("\n"); 73 | } 74 | return 0; 75 | } -------------------------------------------------------------------------------- /Lab-Practise/3a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/Lab-Practise/3a.exe -------------------------------------------------------------------------------- /Lab-Practise/3b.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct Student 3 | { 4 | int studentID; 5 | char name[50]; 6 | char grade; 7 | float marks[5]; 8 | float averageMarks; 9 | }; 10 | 11 | void calculateAverage(struct Student *student) 12 | { 13 | float sum = 0.0; 14 | for (int i = 0; i < 5; i++) 15 | { 16 | sum += student->marks[i]; 17 | } 18 | student->averageMarks = sum / 5; 19 | } 20 | 21 | void assignGrades(struct Student *student) 22 | { 23 | if (student->averageMarks >= 90) 24 | { 25 | student->grade = 'A'; 26 | } 27 | else if (student->averageMarks >= 80) 28 | { 29 | student->grade = 'B'; 30 | } 31 | else if (student->averageMarks >= 70) 32 | { 33 | student->grade = 'C'; 34 | } 35 | else if (student->averageMarks >= 60) 36 | { 37 | student->grade = 'D'; 38 | } 39 | else 40 | { 41 | student->grade = 'F'; 42 | } 43 | } 44 | 45 | int main() 46 | { 47 | struct Student students[5]; 48 | struct Student *studentPtr = students; 49 | for (int i = 0; i < 5; i++) 50 | { 51 | printf("Enter student ID: "); 52 | scanf("%d", &studentPtr->studentID); 53 | printf("Enter Name: "); 54 | scanf("%s", studentPtr->name); 55 | printf("Enter Marks for all 5 Subjects:- \n"); 56 | for (int j = 0; j < 5; j++) 57 | { 58 | printf("Subject %d: ", j + 1); 59 | scanf("$d", &studentPtr->marks[j]); 60 | } 61 | calculateAverage(studentPtr); 62 | assignGrades(studentPtr); 63 | studentPtr++; 64 | } 65 | 66 | studentPtr = students; 67 | printf("\nStudent Details:\n"); 68 | for (int i = 0; i < 5; i++) 69 | { 70 | printf("Student %d\n", i + 1); 71 | printf("Student ID: %d\n", studentPtr->studentID); 72 | printf("Student Name: %s\n", studentPtr->name); 73 | printf("Average Marks: %.2f\n", studentPtr->averageMarks); 74 | printf("Grade: %c\n", studentPtr->grade); 75 | studentPtr++; 76 | } 77 | } -------------------------------------------------------------------------------- /Lab-Practise/3b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/Lab-Practise/3b.exe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C-Language 2 | 3 | -------------------------------------------------------------------------------- /SEE/Re-Revision/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc.exe build active file", 6 | "command": "C:\\mingw64\\bin\\gcc.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /SEE/Re-Revision/Queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Node 5 | { 6 | int data; 7 | struct Node *next; 8 | }; 9 | 10 | struct Queue 11 | { 12 | struct Node *front; 13 | struct Node *rear; 14 | }; 15 | 16 | struct Queue *createQueue() 17 | { 18 | struct Queue *queue = (struct Queue *)malloc(sizeof(struct Queue)); 19 | queue->front = NULL; 20 | queue->rear = NULL; 21 | return queue; 22 | } 23 | 24 | int isEmpty(struct Queue *queue) 25 | { 26 | return queue->front == NULL; 27 | } 28 | 29 | void enqueue(struct Queue *queue, int value) 30 | { 31 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 32 | newNode->data = value; 33 | newNode->next = NULL; 34 | if (queue->front == NULL) 35 | { 36 | queue->front = newNode; 37 | queue->rear = newNode; 38 | } 39 | else 40 | { 41 | queue->rear->next = newNode; 42 | queue->rear = newNode; 43 | } 44 | printf("Enqueued %d to queue\n", value); 45 | } 46 | 47 | int dequeue(struct Queue *queue) 48 | { 49 | if (isEmpty(queue)) 50 | { 51 | printf("Queue is empty\n"); 52 | return -1; 53 | } 54 | struct Node *temp = queue->front; 55 | int dequeuedValue = temp->data; 56 | queue->front = temp->next; 57 | free(temp); 58 | return dequeuedValue; 59 | } 60 | 61 | void display(struct Queue *queue) 62 | { 63 | struct Node *temp = queue->front; 64 | printf("Queue elements are: "); 65 | while (temp != NULL) 66 | { 67 | printf("%d ", temp->data); 68 | temp = temp->next; 69 | } 70 | printf("\n"); 71 | } 72 | 73 | int main() 74 | { 75 | struct Queue *queue = createQueue(); 76 | enqueue(queue, 10); 77 | enqueue(queue, 20); 78 | enqueue(queue, 30); 79 | display(queue); 80 | printf("Dequeued %d from queue\n", dequeue(queue)); 81 | display(queue); 82 | return 0; 83 | } -------------------------------------------------------------------------------- /SEE/Re-Revision/Queue.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/Re-Revision/Queue.exe -------------------------------------------------------------------------------- /SEE/Re-Revision/TowerOfHanoi.c: -------------------------------------------------------------------------------- 1 | void towerofhanoi(int n, char from, char to, char aux) 2 | { 3 | if (n == 1) 4 | { 5 | printf("Disk 1 moved freom %c to %c\n", from, to); 6 | return; 7 | } 8 | towerofhanoi(n - 1, from, aux, to); 9 | prinf("Disk %d moved to %c\n", n, from, to); 10 | towerofhanoi(n - 1, aux, to, from); 11 | } 12 | 13 | int main() 14 | { 15 | int n; 16 | printf("Enter the number of disks: "); 17 | scanf("%d", &n); 18 | towerofhanoi(n, 'A', 'C', 'B'); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /SEE/Re-Revision/bst.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Node 5 | { 6 | int data; 7 | struct Node *left; 8 | struct Node *right; 9 | }; 10 | 11 | struct Node *createNode(int data) 12 | { 13 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 14 | newNode->data = data; 15 | newNode->left = newNode->right = NULL; 16 | return newNode; 17 | } 18 | 19 | struct Node *insertNode(struct Node *root, int data) 20 | { 21 | if (root == NULL) 22 | { 23 | return createNode(data); 24 | } 25 | if (data < root->data) 26 | { 27 | root->left = insertNode(root->left, data); 28 | } 29 | else if (data > root->data) 30 | { 31 | root->right = insertNode(root->right, data); 32 | } 33 | return root; 34 | } 35 | 36 | void inorder(struct Node *root) 37 | { 38 | if (root == NULL) 39 | { 40 | return; 41 | } 42 | inorder(root->left); 43 | printf("%d ", root->data); 44 | inorder(root->right); 45 | } 46 | 47 | void preorder(struct Node *root) 48 | { 49 | if (root == NULL) 50 | { 51 | return; 52 | } 53 | printf("%d ", root->data); 54 | inorder(root->left); 55 | inorder(root->right); 56 | } 57 | 58 | void postorder(struct Node *root) 59 | { 60 | if (root == NULL) 61 | { 62 | return; 63 | } 64 | inorder(root->left); 65 | inorder(root->right); 66 | printf("%d ", root->data); 67 | } 68 | 69 | int main() 70 | { 71 | struct Node *root = NULL; 72 | root = insertNode(root, 50); 73 | insertNode(root, 30); 74 | insertNode(root, 20); 75 | insertNode(root, 40); 76 | insertNode(root, 70); 77 | insertNode(root, 60); 78 | printf("Inorder traversal: "); 79 | inorder(root); 80 | printf("\nPreorder traversal: "); 81 | preorder(root); 82 | printf("\nPostorder traversal: "); 83 | postorder(root); 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /SEE/Re-Revision/bst.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/Re-Revision/bst.exe -------------------------------------------------------------------------------- /SEE/Re-Revision/singly.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Node 5 | { 6 | int data; 7 | struct Node *next; 8 | }; 9 | 10 | struct Node *insertAtBeginning(struct Node *head, int data) 11 | { 12 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 13 | if (newNode == NULL) 14 | { 15 | printf("Memory Error\n"); 16 | return head; 17 | } 18 | newNode->data = data; 19 | newNode->next = head; 20 | return newNode; 21 | } 22 | 23 | struct Node *insertAtEnd(struct Node *head, int data) 24 | { 25 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 26 | if (newNode == NULL) 27 | { 28 | printf("Memory Error\n"); 29 | return head; 30 | } 31 | newNode->data = data; 32 | newNode->next = NULL; 33 | if (head == NULL) 34 | { 35 | return newNode; 36 | } 37 | } 38 | 39 | struct Node *deleteByValue(struct Node *head, int key) 40 | { 41 | if (head == NULL) 42 | { 43 | printf("List is empty\n"); 44 | return head; 45 | } 46 | if (head->data == key) 47 | { 48 | struct Node *temp = head; 49 | head = head->next; 50 | free(temp); 51 | return head; 52 | } 53 | struct Node *current = head; 54 | while (current->next != NULL && current->next->data != key) 55 | { 56 | current = current->next; 57 | } 58 | if (current->next == NULL) 59 | { 60 | printf("Element not found\n"); 61 | return head; 62 | } 63 | struct Node *temp = current->next; 64 | current->next = current->next->next; 65 | free(temp); 66 | 67 | return head; 68 | } 69 | 70 | void display(struct Node *head) 71 | { 72 | struct Node *current = head; 73 | while (current != NULL) 74 | { 75 | printf("%d -> ", current->data); 76 | current = current->next; 77 | } 78 | printf("NULL\n"); 79 | } 80 | 81 | int main() 82 | { 83 | struct Node *head = NULL; 84 | head = insertAtBeginning(head, 7); 85 | head = insertAtBeginning(head, 5); 86 | head = insertAtEnd(head, 10); 87 | display(head); 88 | head = deleteByValue(head, 5); 89 | display(head); 90 | return 0; 91 | } -------------------------------------------------------------------------------- /SEE/Re-Revision/singly.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/Re-Revision/singly.exe -------------------------------------------------------------------------------- /SEE/Re-Revision/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Node 4 | { 5 | int data; 6 | struct Node *next; 7 | }; 8 | 9 | struct Stack 10 | { 11 | struct Node *top; 12 | }; 13 | 14 | struct Stack *createStack() 15 | { 16 | struct Stack *stack = (struct Stack *)malloc(sizeof(struct Stack)); 17 | stack->top == NULL; 18 | return stack; 19 | } 20 | 21 | int isEMpty(struct Stack *stack) 22 | { 23 | return stack->top == NULL; 24 | } 25 | 26 | void push(struct Stack *stack, int value) 27 | { 28 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 29 | newNode->data = value; 30 | newNode->next = stack->top; 31 | stack->top = newNode; 32 | printf("Pushed %d to stack\n", value); 33 | } 34 | 35 | int pop(struct Stack *stack) 36 | { 37 | if (isEMpty(stack)) 38 | { 39 | printf("Stack is empty\n"); 40 | return -1; 41 | } 42 | struct Node *temp = stack->top; 43 | int popped = temp->data; 44 | stack->top = temp->next; 45 | free(temp); 46 | return popped; 47 | } 48 | 49 | int main() 50 | { 51 | struct Stack *stack = createStack(); 52 | push(stack, 10); 53 | push(stack, 20); 54 | push(stack, 30); 55 | printf("Popped %d from stack\n", pop(stack)); 56 | printf("Popped %d from stack\n", pop(stack)); 57 | printf("Popped %d from stack\n", pop(stack)); 58 | printf("Popped %d from stack\n", pop(stack)); 59 | return 0; 60 | } -------------------------------------------------------------------------------- /SEE/Re-Revision/stack.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/Re-Revision/stack.exe -------------------------------------------------------------------------------- /SEE/basic.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter an integer: "); 6 | scanf("%d", &n); 7 | int arr[n]; 8 | for (int i = 0; i < n; i++) 9 | { 10 | printf("Enter element %d: ", i + 1); 11 | scanf("%d", &arr[i]); 12 | } 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /SEE/basic.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/basic.exe -------------------------------------------------------------------------------- /SEE/doubly.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Node 4 | { 5 | int data; 6 | struct Node *next; 7 | struct Node *prev; 8 | } -------------------------------------------------------------------------------- /SEE/hanoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | void towerofhanoi(int n, char from, char to, char aux) 3 | { 4 | if (n == 1) 5 | { 6 | printf("Disk 1 moved from %c to %c\n", from, to); 7 | return; 8 | } 9 | towerofhanoi(n - 1, from, aux, to); 10 | printf("Disk %d moved from %c to %c\n", n, from, to); 11 | towerofhanoi(n - 1, aux, to, from); 12 | } 13 | 14 | int main() 15 | { 16 | int n; 17 | printf("Enter the number of disks: "); 18 | scanf("%d", &n); 19 | towerofhanoi(n, 'A', 'C', 'B'); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /SEE/hanoi.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/hanoi.exe -------------------------------------------------------------------------------- /SEE/queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // Structure to represent a node in the linked list 4 | struct Node 5 | { 6 | int data; 7 | struct Node *next; 8 | }; 9 | // Structure to represent a queue 10 | struct Queue 11 | { 12 | struct Node *front; 13 | struct Node *rear; 14 | }; 15 | // Function to initialize an empty queue 16 | struct Queue *createQueue() 17 | { 18 | struct Queue *queue = (struct Queue *)malloc(sizeof(struct Queue)); 19 | queue->front = queue->rear = NULL; 20 | return queue; 21 | } 22 | // Function to check if the queue is empty 23 | int isEmpty(struct Queue *queue) 24 | { 25 | return (queue->front == NULL); 26 | } 27 | // Function to enqueue an element to the rear of the queue 28 | void enqueue(struct Queue *queue, int data) 29 | { 30 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 31 | newNode->data = data; 32 | newNode->next = NULL; 33 | if (isEmpty(queue)) 34 | { 35 | queue->front = queue->rear = newNode; 36 | } 37 | else 38 | { 39 | queue->rear->next = newNode; 40 | queue->rear = newNode; 41 | } 42 | } 43 | // Function to dequeue an element from the front of the queue 44 | int dequeue(struct Queue *queue) 45 | { 46 | if (isEmpty(queue)) 47 | { 48 | printf("Queue underflow: Cannot dequeue from an empty queue.\n"); 49 | return -1; // Error value 50 | } 51 | struct Node *temp = queue->front; 52 | int data = temp->data; 53 | queue->front = queue->front->next; 54 | free(temp); 55 | return data; 56 | } 57 | // Function to display the elements of the queue 58 | void display(struct Queue *queue) 59 | { 60 | if (isEmpty(queue)) 61 | { 62 | printf("Queue is empty.\n"); 63 | return; 64 | } 65 | struct Node *current = queue->front; 66 | printf("Queue elements: "); 67 | while (current != NULL) 68 | { 69 | printf("%d ", current->data); 70 | current = current->next; 71 | } 72 | printf("\n"); 73 | } 74 | int main() 75 | { 76 | struct Queue *queue = createQueue(); 77 | enqueue(queue, 10); 78 | enqueue(queue, 20); 79 | enqueue(queue, 30); 80 | display(queue); 81 | printf("Dequeued element: %d\n", dequeue(queue)); 82 | display(queue); 83 | printf("Is the queue empty? %s\n", isEmpty(queue) ? "Yes" : "No"); 84 | return 0; 85 | } -------------------------------------------------------------------------------- /SEE/queue.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/queue.exe -------------------------------------------------------------------------------- /SEE/singly.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // Define a structure for a node in the linked list 4 | struct Node 5 | { 6 | int data; 7 | struct Node *next; 8 | }; 9 | // Function to insert a node at the beginning of the list 10 | struct Node *insertAtBeginning(struct Node *head, int value) 11 | { 12 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 13 | if (newNode == NULL) 14 | { 15 | printf("Memory allocation failed.\n"); 16 | return head; 17 | } 18 | newNode->data = value; 19 | newNode->next = head; 20 | return newNode; 21 | } 22 | // Function to insert a node at the end of the list 23 | struct Node *insertAtEnd(struct Node *head, int value) 24 | { 25 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 26 | if (newNode == NULL) 27 | { 28 | printf("Memory allocation failed.\n"); 29 | return head; 30 | } 31 | newNode->data = value; 32 | newNode->next = NULL; 33 | if (head == NULL) 34 | { 35 | return newNode; 36 | } 37 | struct Node *current = head; 38 | while (current->next != NULL) 39 | { 40 | current = current->next; 41 | } 42 | current->next = newNode; 43 | return head; 44 | } 45 | // Function to delete a node by value 46 | struct Node *deleteByValue(struct Node *head, int value) 47 | { 48 | if (head == NULL) 49 | { 50 | printf("List is empty. Cannot delete.\n"); 51 | return head; 52 | } 53 | if (head->data == value) 54 | { 55 | struct Node *temp = head; 56 | head = head->next; 57 | free(temp); 58 | return head; 59 | } 60 | struct Node *current = head; 61 | while (current->next != NULL && current->next->data != value) 62 | { 63 | current = current->next; 64 | } 65 | if (current->next == NULL) 66 | { 67 | printf("Value not found in the list. Cannot delete.\n"); 68 | return head; 69 | } 70 | struct Node *temp = current->next; 71 | current->next = current->next->next; 72 | free(temp); 73 | return head; 74 | } 75 | // Function to display the linked list 76 | void displayList(struct Node *head) 77 | { 78 | printf("Linked List: "); 79 | struct Node *current = head; 80 | while (current != NULL) 81 | { 82 | printf("%d -> ", current->data); 83 | current = current->next; 84 | } 85 | printf("NULL\n"); 86 | } 87 | int main() 88 | { 89 | struct Node *head = NULL; 90 | int choice, value; 91 | while (1) 92 | { 93 | printf("\nMenu:\n"); 94 | printf("1. Insert at the beginning\n"); 95 | printf("2. Insert at the end\n"); 96 | printf("3. Delete by value\n"); 97 | printf("4. Display\n"); 98 | printf("5. Exit\n"); 99 | printf("Enter your choice: "); 100 | scanf("%d", &choice); 101 | switch (choice) 102 | { 103 | case 1: 104 | printf("Enter a value to insert: "); 105 | scanf("%d", &value); 106 | head = insertAtBeginning(head, value); 107 | break; 108 | case 2: 109 | printf("Enter a value to insert: "); 110 | scanf("%d", &value); 111 | head = insertAtEnd(head, value); 112 | break; 113 | case 3: 114 | printf("Enter a value to delete: "); 115 | scanf("%d", &value); 116 | head = deleteByValue(head, value); 117 | break; 118 | case 4: 119 | displayList(head); 120 | break; 121 | case 5: 122 | // Clean up and exit 123 | while (head != NULL) 124 | { 125 | struct Node *temp = head; 126 | head = head->next; 127 | free(temp); 128 | } 129 | return 0; 130 | default: 131 | printf("Invalid choice. Please try again.\n"); 132 | } 133 | } 134 | return 0; 135 | } -------------------------------------------------------------------------------- /SEE/singly.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/singly.exe -------------------------------------------------------------------------------- /SEE/sparse.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int sparse[6][6] = {{0, 0, 1, 0, 2, 0}, 5 | {0, 3, 0, 0, 0, 0}, 6 | {0, 0, 0, 0, 0, 4}, 7 | {0, 0, 5, 0, 0, 0}, 8 | {0, 0, 0, 6, 0, 0}, 9 | {0, 0, 0, 0, 7, 0}}; 10 | int size = 0; 11 | for (int i = 0; i < 6; i++) 12 | { 13 | for (int j = 0; j < 6; j++) 14 | { 15 | if (sparse[i][j] != 0) 16 | { 17 | size++; 18 | } 19 | } 20 | } 21 | 22 | int matrix[3][size]; 23 | int k = 0; 24 | for (int i = 0; i < 6; i++) 25 | { 26 | for (int j = 0; j < 6; j++) 27 | { 28 | if (sparse[i][j] != 0) 29 | { 30 | matrix[0][k] = sparse[i][j]; 31 | matrix[1][k] = i; 32 | matrix[2][k] = j; 33 | k++; 34 | } 35 | } 36 | } 37 | printf("%-8s %-8s %-8s", "Value", "Row", "Column"); 38 | for (int i = 0; i < size; i++) 39 | { 40 | printf("\n%-8d %-8d %-8d", matrix[0][i], matrix[1][i] + 1, matrix[2][i] + 1); 41 | } 42 | } -------------------------------------------------------------------------------- /SEE/sparse.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/sparse.exe -------------------------------------------------------------------------------- /SEE/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Node 4 | { 5 | int data; 6 | struct Node *next; 7 | }; 8 | 9 | struct Stack 10 | { 11 | struct Node *top; 12 | }; 13 | 14 | struct Stack *createStack() 15 | { 16 | struct Stack *stack = (struct Stack *)malloc(sizeof(struct Stack)); 17 | stack->top = NULL; 18 | return stack; 19 | } 20 | 21 | int isEmpty(struct Stack *stack) 22 | { 23 | return (stack->top == NULL); 24 | } 25 | 26 | void push(struct Stack *stack, int data) 27 | { 28 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 29 | newNode->data = data; 30 | newNode->next = stack->top; 31 | stack->top = newNode; 32 | printf("%d pushed to stack\n", data); 33 | } 34 | 35 | int pop(struct Stack *stack) 36 | { 37 | if (isEmpty(stack)) 38 | { 39 | printf("Stack is empty\n"); 40 | return -1; 41 | } 42 | struct Node *temp = stack->top; 43 | int popped = temp->data; 44 | stack->top = temp->next; 45 | free(temp); 46 | return popped; 47 | } 48 | 49 | int main() 50 | { 51 | struct Stack *stack = createStack(); 52 | 53 | push(stack, 10); 54 | push(stack, 20); 55 | push(stack, 30); 56 | printf("Popped element is %d\n", pop(stack)); 57 | printf("Popped element is %d\n", pop(stack)); 58 | return 0; 59 | } -------------------------------------------------------------------------------- /SEE/stack.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/stack.exe -------------------------------------------------------------------------------- /SEE/struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct student 4 | { 5 | char name[20]; 6 | int age; 7 | float percentage; 8 | }; 9 | 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the number of students: "); 14 | scanf("%d", &n); 15 | struct student s[n]; 16 | struct student *p[n]; 17 | for (int i = 0; i < n; i++) 18 | { 19 | p[i] = &s[i]; 20 | } 21 | for (int i = 0; i < n; i++) 22 | { 23 | printf("Enter the name of the student: "); 24 | scanf("%s", p[i]->name); 25 | printf("Enter the age of the student: "); 26 | scanf("%d", &p[i]->age); 27 | printf("Enter the percentage of the student: "); 28 | scanf("%f", &p[i]->percentage); 29 | } 30 | printf("\nStudent Details:\n"); 31 | for (int i = 0; i < n; i++) 32 | { 33 | printf("Name: %s\n", p[i]->name); 34 | printf("Age: %d\n", p[i]->age); 35 | printf("Percentage: %.2f\n", p[i]->percentage); 36 | printf("\n"); 37 | } 38 | } -------------------------------------------------------------------------------- /SEE/struct.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/SEE/struct.exe -------------------------------------------------------------------------------- /Test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // Define a structure for a node in the linked list 4 | struct Node 5 | { 6 | int data; 7 | struct Node *next; 8 | }; 9 | // Function to insert a node at the beginning of the list 10 | struct Node *insertAtBeginning(struct Node *head, int value) 11 | { 12 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 13 | if (newNode == NULL) 14 | { 15 | printf("Memory allocation failed.\n"); 16 | return head; 17 | } 18 | newNode->data = value; 19 | newNode->next = head; 20 | return newNode; 21 | } 22 | // Function to insert a node at the end of the list 23 | struct Node *insertAtEnd(struct Node *head, int value) 24 | { 25 | struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); 26 | if (newNode == NULL) 27 | { 28 | printf("Memory allocation failed.\n"); 29 | return head; 30 | } 31 | newNode->data = value; 32 | newNode->next = NULL; 33 | if (head == NULL) 34 | { 35 | return newNode; 36 | } 37 | struct Node *current = head; 38 | while (current->next != NULL) 39 | { 40 | current = current->next; 41 | } 42 | current->next = newNode; 43 | return head; 44 | } 45 | // Function to delete a node by value 46 | struct Node *deleteByValue(struct Node *head, int value) 47 | { 48 | if (head == NULL) 49 | { 50 | printf("List is empty. Cannot delete.\n"); 51 | return head; 52 | } 53 | if (head->data == value) 54 | { 55 | struct Node *temp = head; 56 | head = head->next; 57 | free(temp); 58 | return head; 59 | } 60 | struct Node *current = head; 61 | while (current->next != NULL && current->next->data != value) 62 | { 63 | current = current->next; 64 | } 65 | if (current->next == NULL) 66 | { 67 | printf("Value not found in the list. Cannot delete.\n"); 68 | return head; 69 | } 70 | struct Node *temp = current->next; 71 | current->next = current->next->next; 72 | free(temp); 73 | return head; 74 | } 75 | // Function to display the linked list 76 | void displayList(struct Node *head) 77 | { 78 | printf("Linked List: "); 79 | struct Node *current = head; 80 | while (current != NULL) 81 | { 82 | printf("%d -> ", current->data); 83 | current = current->next; 84 | } 85 | printf("NULL\n"); 86 | } 87 | int main() 88 | { 89 | struct Node *head = NULL; 90 | int choice, value; 91 | while (1) 92 | { 93 | printf("\nMenu:\n"); 94 | printf("1. Insert at the beginning\n"); 95 | printf("2. Insert at the end\n"); 96 | printf("3. Delete by value\n"); 97 | printf("4. Display\n"); 98 | printf("5. Exit\n"); 99 | printf("Enter your choice: "); 100 | scanf("%d", &choice); 101 | switch (choice) 102 | { 103 | case 1: 104 | printf("Enter a value to insert: "); 105 | scanf("%d", &value); 106 | head = insertAtBeginning(head, value); 107 | break; 108 | case 2: 109 | printf("Enter a value to insert: "); 110 | scanf("%d", &value); 111 | head = insertAtEnd(head, value); 112 | break; 113 | case 3: 114 | printf("Enter a value to delete: "); 115 | scanf("%d", &value); 116 | head = deleteByValue(head, value); 117 | break; 118 | case 4: 119 | displayList(head); 120 | break; 121 | case 5: 122 | // Clean up and exit 123 | while (head != NULL) 124 | { 125 | struct Node *temp = head; 126 | head = head->next; 127 | free(temp); 128 | } 129 | return 0; 130 | default: 131 | printf("Invalid choice. Please try again.\n"); 132 | } 133 | } 134 | return 0; 135 | } -------------------------------------------------------------------------------- /Test.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Language/048e83e061c313d2111193ccb636aa9d9bed3bad/Test.exe --------------------------------------------------------------------------------