├── DS UNIT 4,5.pdf ├── Assignment-8 ├── README.md ├── BinaryHeap-Prog-Assign8.docx ├── application.c ├── basic.c ├── adt.h └── adt1.h ├── Tutorial-2 └── Tutorial 2.docx ├── Assignment 1 ├── Pointers-Experiments.pdf ├── ArrayADT-Prog-Assign1.docx ├── A1_7.c ├── A1_1.c ├── A1_3.c ├── A1_4.c ├── A1_2.c ├── A1_6.c ├── A1_9.c ├── A1_5.c ├── Assignment1.c ├── arrADT.h └── A1_8.c ├── Assignment 2 ├── ListADT-Prog-Assign2.docx ├── polynomial.c ├── LINKEDLIST.c ├── polyABT.h └── ABT.h ├── Assignment-5 ├── BST-ADT-Prog-Assign5.docx ├── Application │ ├── Application3.c │ ├── Application2.c │ ├── Application1.c │ ├── Application1ADT.h │ ├── Application3ADT.h │ └── Application2ADT.h ├── BinarySearchTree_Basic.c └── ADT.h ├── Assignment-7 ├── AVLTree-Prog-Assign7.docx ├── AVLtree.c └── avlADT.h ├── Tutorial-1 └── Karthikeyan 5001 041 DS.pdf ├── Assignment-3 ├── StackADT-Prog-Assign3.docx ├── BinaryApplication.c ├── MaxApplication.c ├── PostfixApplicationADT.h ├── Stack.c ├── PostfixApplication.c └── ADT.h ├── Assignment-4 ├── QueueADT-Prog-Assign4.docx ├── Queue.c ├── queue using array │ ├── Queue using array.c │ └── qADTa.h ├── QueueADT.h └── Application │ ├── jobADT.h │ └── Job scheduling.c ├── Assignment-10 ├── ShortestPath-Prog-Assign10.docx ├── dijsktras.c ├── main.c └── dijsktrasgraph.h ├── Assignment-6 ├── DoublyLinkedList-Prog-Assign6.docx ├── Application1.c ├── Double.c ├── Application │ ├── Application3.c │ ├── Application2.c │ ├── Application1.c │ ├── Application3ADT.h │ ├── Application2ADT.h │ └── Application1ADT.h └── ADT.h ├── All Data Structure ├── Double Linked List │ ├── Double Linked List PDF.pdf │ ├── Double Linked List Introduction.pptm │ ├── DoubleADT.h │ └── Double Linked List.c ├── Circular Linked List │ ├── Circular Linked List PDF.pdf │ ├── 3 Circular Linked List Introduction.pptx │ ├── Circular Linked List.c │ └── ADT.h ├── Simple Linked List │ ├── 2 Linked List Introduction.pptx │ ├── LinkedList.c │ └── LinkedListADT.h ├── GRAPH │ ├── main.c │ ├── Queue.h │ ├── Stack.h │ └── graph.h ├── Queue using array implementation │ ├── main.c │ └── Queue.h ├── AVL │ ├── avl.c │ └── avlADT.h ├── Stack using array implementation │ ├── Stack.c │ └── StackADT.h ├── Priarity_Queue │ ├── PriarityQueue.c │ └── PriarityQueueADT.h ├── GRAPH Appliactions │ ├── main.c │ └── graph.h ├── BST │ ├── BinarySearchTree.c │ ├── queue.h │ └── BinarySearchTreeADT.h ├── Array Data Structure │ ├── Array.c │ └── ArrayADT.h └── README.md ├── Assignment-9 ├── main.c ├── Application │ ├── main.c │ ├── mainA2.c │ ├── Queue.h │ ├── Stack.h │ ├── Application2.h │ └── Application1.h ├── Queue.h ├── Stack.h └── graph.h ├── Assignment-12 ├── main.c ├── hashTADT.h └── Application │ ├── applic.h │ └── main.c ├── Assignment-11 ├── Application │ ├── sort.c │ └── SellsortADT.h ├── sort.c ├── arrADT.h └── SellsortADT.h ├── Tutorial-3 └── State_Capital_application.c └── README.md /DS UNIT 4,5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/DS UNIT 4,5.pdf -------------------------------------------------------------------------------- /Assignment-8/README.md: -------------------------------------------------------------------------------- 1 | # Run this program using this command 2 | 3 | ## gcc filename.c -o out -lm 4 | ## ./out 5 | -------------------------------------------------------------------------------- /Tutorial-2/Tutorial 2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Tutorial-2/Tutorial 2.docx -------------------------------------------------------------------------------- /Assignment 1/Pointers-Experiments.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment 1/Pointers-Experiments.pdf -------------------------------------------------------------------------------- /Assignment 2/ListADT-Prog-Assign2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment 2/ListADT-Prog-Assign2.docx -------------------------------------------------------------------------------- /Assignment-5/BST-ADT-Prog-Assign5.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment-5/BST-ADT-Prog-Assign5.docx -------------------------------------------------------------------------------- /Assignment-7/AVLTree-Prog-Assign7.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment-7/AVLTree-Prog-Assign7.docx -------------------------------------------------------------------------------- /Tutorial-1/Karthikeyan 5001 041 DS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Tutorial-1/Karthikeyan 5001 041 DS.pdf -------------------------------------------------------------------------------- /Assignment 1/ArrayADT-Prog-Assign1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment 1/ArrayADT-Prog-Assign1.docx -------------------------------------------------------------------------------- /Assignment-3/StackADT-Prog-Assign3.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment-3/StackADT-Prog-Assign3.docx -------------------------------------------------------------------------------- /Assignment-4/QueueADT-Prog-Assign4.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment-4/QueueADT-Prog-Assign4.docx -------------------------------------------------------------------------------- /Assignment-8/BinaryHeap-Prog-Assign8.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment-8/BinaryHeap-Prog-Assign8.docx -------------------------------------------------------------------------------- /Assignment-10/ShortestPath-Prog-Assign10.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment-10/ShortestPath-Prog-Assign10.docx -------------------------------------------------------------------------------- /Assignment-6/DoublyLinkedList-Prog-Assign6.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/Assignment-6/DoublyLinkedList-Prog-Assign6.docx -------------------------------------------------------------------------------- /All Data Structure/Double Linked List/Double Linked List PDF.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/All Data Structure/Double Linked List/Double Linked List PDF.pdf -------------------------------------------------------------------------------- /All Data Structure/Circular Linked List/Circular Linked List PDF.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/All Data Structure/Circular Linked List/Circular Linked List PDF.pdf -------------------------------------------------------------------------------- /All Data Structure/Simple Linked List/2 Linked List Introduction.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/All Data Structure/Simple Linked List/2 Linked List Introduction.pptx -------------------------------------------------------------------------------- /All Data Structure/Double Linked List/Double Linked List Introduction.pptm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/All Data Structure/Double Linked List/Double Linked List Introduction.pptm -------------------------------------------------------------------------------- /Assignment 1/A1_7.c: -------------------------------------------------------------------------------- 1 | /* 2 | 7. Create NULL pointer and print the value of it. 3 | */ 4 | #include 5 | void main() 6 | { 7 | int *ptr = NULL; 8 | printf("pointer value = %p \n",ptr); 9 | } 10 | -------------------------------------------------------------------------------- /All Data Structure/Circular Linked List/3 Circular Linked List Introduction.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkbughunter/Data-Structure/HEAD/All Data Structure/Circular Linked List/3 Circular Linked List Introduction.pptx -------------------------------------------------------------------------------- /Assignment-9/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"graph.h" 4 | 5 | int main(){ 6 | 7 | struct graph *gr = create_graph(); 8 | int st; 9 | printf("Enter the starting point : "); 10 | scanf("%d",&st); 11 | BFS(gr,st); 12 | DFS(gr,st); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /All Data Structure/GRAPH/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"graph.h" 4 | 5 | int main(){ 6 | 7 | struct graph *gr = create_graph(); 8 | int st; 9 | printf("Enter the starting point : "); 10 | scanf("%d",&st); 11 | BFS(gr,st); 12 | DFS(gr,st); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Assignment 1/A1_1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Initialize integer variable x with 10. Create an integer pointer to x. Print the value of x using x and pointer variable 3 | */ 4 | #include 5 | void main() 6 | { 7 | int x=10; 8 | int *ptrx = &x; 9 | printf("value of x = %d \n",x); 10 | printf("pointer to x = %d \n",*ptrx); 11 | } 12 | -------------------------------------------------------------------------------- /All Data Structure/Queue using array implementation/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Queue.h" 4 | 5 | int main() 6 | { 7 | 8 | struct queue *q = createQueue(5); 9 | enqueue(q,10); 10 | enqueue(q,20); 11 | enqueue(q,30); 12 | display(q); 13 | dequeue(q); 14 | display(q); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Assignment-3/BinaryApplication.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include 5 | #include 6 | #include "ADT.h" 7 | 8 | 9 | int main(){ 10 | struct stack *head = (struct stack*) malloc(sizeof(struct stack)); 11 | printf("3) Binary Application\n "); 12 | 13 | createStack(head, 10); 14 | Binary(head,14); 15 | printf("\n"); 16 | return 0; 17 | 18 | 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Assignment 1/A1_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3. Initialize array. Print the contents of the using address of the contents 3 | */ 4 | #include 5 | void main() 6 | { 7 | int i=0,arr[] = {5,10,15,20,25,30,35,40}; 8 | 9 | printf("Array elements are : { "); 10 | int n = sizeof(arr)/sizeof(int); 11 | while(*(arr+i) != *(arr+n)){ 12 | printf("%d ",*(arr+i)); 13 | i++; 14 | } 15 | printf("}\n"); 16 | return ; 17 | } 18 | -------------------------------------------------------------------------------- /Assignment-9/Application/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Application2.h" 4 | 5 | int main(){ 6 | 7 | struct graph *gr = create_graph(); 8 | int st,di; 9 | printf("Enter the starting point : "); 10 | scanf("%d",&st); 11 | printf("Enter the Ending point : "); 12 | scanf("%d",&di); 13 | BFS(gr,st,di); 14 | // DFS(gr,st); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Assignment 1/A1_4.c: -------------------------------------------------------------------------------- 1 | /* 2 | 4. Find the largest number in the array which you have created in Ex. 3 3 | */ 4 | #include 5 | void main() 6 | { 7 | int i=0,arr[] = {5,10,15,20,25,30,35,40}; 8 | int max = arr[0]; 9 | int n = sizeof(arr)/sizeof(int); 10 | 11 | while(*(arr+i) != *(arr+n)){ 12 | if(max < *(arr+i)) max = *(arr+i); 13 | i++; 14 | } 15 | printf("Max value : %d\n\n",max); 16 | return ; 17 | } 18 | -------------------------------------------------------------------------------- /Assignment-3/MaxApplication.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ADT.h" 4 | 5 | 6 | int main(){ 7 | struct stack *head = (struct stack*) malloc(sizeof(struct stack)); 8 | printf("Elements :"); 9 | createStack(head, 10); 10 | push(head,1); 11 | push(head,2); 12 | push(head,3); 13 | display(head); 14 | printf("\n\n %d is max value\n\n",big(head)); 15 | return 0; 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Assignment-9/Application/mainA2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Application2.h" 4 | 5 | int main(){ 6 | 7 | struct graph *gr = create_graph(); 8 | int st, di, i=0, visit[gr->vertex]; 9 | for(i=0; ivertex; i++) visit[i]=0; 10 | for(i=0; ivertex; i++){ 11 | if(visit[i] == 0 ){ 12 | BFS(gr,i+1,visit); 13 | } 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Assignment 1/A1_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 2. Increment the variable x and access through pointer variable. Increment pointer variable and access through pointer variable 3 | */ 4 | 5 | #include 6 | void main() 7 | { 8 | int x = 10; 9 | int *ptr = &x; 10 | printf("Accessing through Pointer (Before update): %d\n",*ptr); 11 | *ptr +=10; 12 | printf("Accessing through Pointer (After update) : %d\n",*ptr); 13 | return ; 14 | } 15 | -------------------------------------------------------------------------------- /All Data Structure/AVL/avl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"avlADT.h" 4 | 5 | int main() 6 | { 7 | struct avl *t=NULL; 8 | t = Insert(t, 10); 9 | t = Insert(t, 8); 10 | t = Insert(t, 9); 11 | t = Insert(t, 19); 12 | printf("\n\n"); 13 | inorder(t); 14 | printf("\n\n"); 15 | 16 | levelOrderTraversal(t); 17 | return 0; 18 | } 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Assignment 1/A1_6.c: -------------------------------------------------------------------------------- 1 | /* 2 | 6. Use the example 1, create another pointer variable and copy the address of the already existing pointer variable. Print the data accessed through both the pointers 3 | */ 4 | #include 5 | void main() 6 | { 7 | int x=10; 8 | int *ptr1 = &x; 9 | int *ptr2 = ptr1; 10 | printf("value of x = %d \n",x); 11 | printf("pointer1 = %d \n",*ptr1); 12 | printf("pointer2 = %d \n",*ptr2); 13 | } 14 | -------------------------------------------------------------------------------- /Assignment-4/Queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "QueueADT.h" 4 | 5 | int main(){ 6 | struct node *ptr[2]; 7 | ptr[0] = (struct node*)malloc(sizeof(struct node)); 8 | ptr[1] = (struct node*)malloc(sizeof(struct node)); 9 | createQueue(ptr,"3"); 10 | enqueue(ptr,"J1",3); 11 | enqueue(ptr,"J2",5); 12 | enqueue(ptr,"J3",13); 13 | dequeue(ptr); 14 | enqueue(ptr,"J4",33); 15 | display(ptr); 16 | } 17 | -------------------------------------------------------------------------------- /Assignment 1/A1_9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include"ADT.h" 5 | 6 | void main() 7 | { 8 | int n =10; 9 | struct student *ptr = (struct student*) malloc(n * sizeof(struct student)); 10 | int array[30] = {1,2,3,4,5,6,7,8}; 11 | 12 | int array1[30] = {5,6,7,8}; 13 | 14 | create(ptr, array, 8); 15 | create(ptr+1, array1, 4); 16 | 17 | display(ptr); 18 | display(ptr+1); 19 | 20 | return ; 21 | } 22 | -------------------------------------------------------------------------------- /All Data Structure/Stack using array implementation/Stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Stack.h" 4 | 5 | int main(){ 6 | 7 | struct stack *s = createStack(5); 8 | push(s,10); 9 | push(s,20); 10 | pop(s); 11 | pop(s); 12 | pop(s); 13 | pop(s); 14 | push(s,20); 15 | push(s,10); 16 | push(s,10); 17 | push(s,10); 18 | push(s,10); 19 | displayStack(s); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /All Data Structure/Simple Linked List/LinkedList.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "LinkedListADT.h" 5 | int main(){ 6 | 7 | struct node *head; 8 | head = NULL; 9 | 10 | head = create(head); 11 | insertFrent(head, 1); 12 | insertFrent(head, 2); 13 | insertFrent(head, 3); 14 | insertEnd(head, 4); 15 | insertByKey(head,2,100); 16 | insertEnd(head, 5); 17 | insertPos(head,3,6); 18 | deleteFrent(head); 19 | deleteEnd(head); 20 | deleteKey(head,5); 21 | display(head); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Assignment 1/A1_5.c: -------------------------------------------------------------------------------- 1 | /* 2 | 5. Initialize integer variable x with 10. Create an integer pointer to x. Print the value of x using x and pointer variable. Write change function which will change the value of x. (use pointer) 3 | */ 4 | #include 5 | 6 | void change(int *x); 7 | void change(int *x){ 8 | *x = *x + 15; 9 | } 10 | void main() 11 | { 12 | int x=10; 13 | 14 | printf("Before Calling Funcoiton x Value : %d\n\n",x); 15 | change(&x); 16 | printf("After Calling Funcoiton x Value : %d\n\n",x); 17 | return ; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Assignment-7/AVLtree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "avlADT.h" 4 | 5 | 6 | 7 | int main() 8 | { 9 | struct avltree *t=NULL; 10 | 11 | printf("\n\nInorder :"); 12 | t = insert(t,'H'); 13 | t = insert(t,'I'); 14 | t = insert(t,'J'); 15 | t = insert(t,'B'); 16 | t = insert(t,'A'); 17 | t = insert(t,'E'); 18 | t = insert(t,'C'); 19 | t = insert(t,'F'); 20 | t = insert(t,'D'); 21 | t = insert(t,'G'); 22 | t = insert(t,'K'); 23 | t = insert(t,'L'); 24 | inorder(t); 25 | printf("\n\n"); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Assignment-10/dijsktras.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dijsktrasgraph.h" 4 | 5 | void path(struct graph *gr, int source, int destination){ 6 | 7 | } 8 | int main() 9 | { 10 | struct graph *g = create_graph(); 11 | int *distance = dijkstra(g, 0); 12 | 13 | displayTable(g,distance); 14 | return 0; 15 | } 16 | 17 | /* 18 | Test case 1 19 | 20 | 7 12 21 | v1 22 | v2 23 | v3 24 | v4 25 | v5 26 | v6 27 | v7 28 | 1 4 1 29 | 1 2 2 30 | 2 4 3 31 | 2 5 10 32 | 5 7 6 33 | 7 6 1 34 | 3 1 4 35 | 3 6 5 36 | 4 3 2 37 | 4 5 2 38 | 4 7 4 39 | 4 6 8 40 | 41 | */ -------------------------------------------------------------------------------- /All Data Structure/Circular Linked List/Circular Linked List.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"ADT.h" 4 | 5 | int main(){ 6 | struct node *head; 7 | head = (struct node *) malloc(sizeof(struct node)); 8 | 9 | head->next = NULL; 10 | add(head, 32); 11 | add(head, 43); 12 | add(head, 56); 13 | add(head, 98); 14 | add(head, 1); 15 | display(head); 16 | deletePos(head,32); 17 | display(head); 18 | sortL(head); 19 | display(head); 20 | reverseList(head); 21 | display(head); 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Assignment-12/main.c: -------------------------------------------------------------------------------- 1 | #include "hashTADT.h" 2 | int main() 3 | { 4 | int size, op, elmt, s; 5 | struct hashTable *H; 6 | H = (struct hashTable *)malloc(sizeof(struct hashTable)); 7 | printf("\nEnter the size of the Hash Table : "); 8 | scanf("%d", &size); 9 | init(H, size); 10 | 11 | insert(H, 23); 12 | insert(H, 45); 13 | insert(H, 69); 14 | insert(H, 87); 15 | insert(H, 48); 16 | insert(H, 67); 17 | insert(H, 54); 18 | insert(H, 66); 19 | insert(H, 53); 20 | 21 | display(H); 22 | return 0; 23 | } 24 | // Thank you Jaanu sri 25 | -------------------------------------------------------------------------------- /Assignment-6/Application1.c: -------------------------------------------------------------------------------- 1 | #include"Application1ADT.h" 2 | 3 | void main() { 4 | int result; 5 | 6 | 7 | struct node *h1; 8 | h1 = (struct node *)malloc(sizeof(struct node)); 9 | 10 | insertFront(h1,'D'); // DATA 11 | insertFront(h1,'A'); 12 | insertFront(h1,'T'); 13 | insertFront(h1,'A'); 14 | 15 | displayItems(h1); 16 | 17 | printf("\n"); 18 | 19 | result=isPalindrome(h1); 20 | 21 | if(result==1) 22 | printf("The given list is Palindrome\n"); 23 | else 24 | printf("The given list is not Palindrome\n"); 25 | } 26 | -------------------------------------------------------------------------------- /Assignment-6/Double.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include"ADT.h" 6 | 7 | 8 | int main() { 9 | struct node *h; 10 | h = (struct node *)malloc(sizeof(struct node)); 11 | insertFront(h,'P'); 12 | insertFront(h,'Q'); 13 | insertFront(h,'R'); 14 | insertFront(h,'S'); 15 | insertFront(h,'T'); 16 | insertFront(h,'U'); 17 | insertFront(h,'V'); 18 | insertFront(h,'W'); 19 | insertFront(h,'X'); 20 | insertFront(h,'Y'); 21 | insertFront(h,'Z'); 22 | 23 | displayItems(h); 24 | 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Assignment-6/Application/Application3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include"Application3ADT.h" 5 | 6 | int main() { 7 | struct node *h; 8 | int node; 9 | h = (struct node *)malloc(sizeof(struct node)); 10 | 11 | insertFront(h,'A'); 12 | insertFront(h,'B'); 13 | insertFront(h,'C'); 14 | insertFront(h,'D'); 15 | insertFront(h,'E'); 16 | 17 | 18 | display(h); 19 | printf("\n"); 20 | 21 | printf("Enter the node number to be swaped:"); 22 | scanf("%d",&node); 23 | 24 | swap(h,node); 25 | display(h); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /All Data Structure/Priarity_Queue/PriarityQueue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "PriarityQueueADT.h" 4 | int main() 5 | { 6 | struct PriarityQueueADT *pq = NULL; 7 | pq = init(pq,10); 8 | Insert(pq,1); 9 | Insert(pq,2); 10 | Insert(pq,3); 11 | Insert(pq,4); 12 | Insert(pq,5); 13 | Insert(pq,0); 14 | Display(pq); 15 | Delete(pq); 16 | Delete(pq); 17 | Delete(pq); 18 | Delete(pq); 19 | Delete(pq); 20 | Delete(pq); 21 | Delete(pq); 22 | Display(pq); 23 | Insert(pq,5); 24 | Insert(pq,2); 25 | Insert(pq,3); 26 | Display(pq); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /All Data Structure/GRAPH Appliactions/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"graph.h" 4 | 5 | int main(){ 6 | 7 | struct graph *gr = create_graph(); 8 | int st, **table; 9 | printf("Enter the starting point : "); 10 | scanf("%d",&st); 11 | st--; 12 | table = dijkstra(gr,st); 13 | 14 | printf("Enter the Ending point : "); 15 | scanf("%d",&st); 16 | st--; 17 | printPath(gr,table,st); 18 | return 0; 19 | } 20 | 21 | 22 | /* 23 | Test case 3 24 | 6 7 25 | 1 6 26 | 6 2 27 | 6 5 28 | 5 4 29 | 4 3 30 | 2 3 31 | 2 1 32 | Chennai 33 | Oouty 34 | Selam 35 | Ambur 36 | Theni 37 | Maduri 38 | 1 39 | 4 40 | 41 | */ -------------------------------------------------------------------------------- /All Data Structure/BST/BinarySearchTree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "BinarySearchTreeADT.h" 4 | 5 | int main() 6 | { 7 | struct tree *t = NULL; 8 | t = insertBST(t,30); 9 | t = insertBST(t,20); 10 | t = insertBST(t,40); 11 | t = insertBST(t,10); 12 | t = insertBST(t,15); 13 | t = insertBST(t,35); 14 | t = insertBST(t,50); 15 | inorderBST(t); 16 | printf("\nStart delete :\n"); 17 | t = deleteBST(t,20); 18 | t = deleteBST(t,40); 19 | t = deleteBST(t,10); 20 | t = deleteBST(t,15); 21 | inorderBST(t); 22 | // printf("\n\nLevel Order \n\n "); 23 | // levelorderBST(t); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Assignment 1/Assignment1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "arrADT.h" 4 | 5 | int main() 6 | { 7 | struct node *head; 8 | int array[]= {2,4,6,8,10},size=5; 9 | head = (struct node*) malloc(sizeof(struct node)); 10 | create(head,size,array); 11 | printf("\nAfter Create : "); 12 | printArray(head); 13 | int pos = 3; 14 | deleteAt(head, pos ); 15 | printf("\nAfter Delete : "); 16 | printArray(head); 17 | int key = 1; 18 | insertAtEvery(head,key); 19 | printf("\nAfter Insert : "); 20 | printArray(head); 21 | key =1; 22 | int result = search(head,key); 23 | printf("\nYour value in position : %d\n\n\t\tThank you",result); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Assignment-11/Application/sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "SellsortADT.h" 4 | 5 | int main() 6 | { 7 | struct node1 *head1; 8 | int array1[]= {1,2,3,4,1,1,1},size1=7; 9 | head1 = (struct node1*) malloc(sizeof(struct node1)); 10 | 11 | init(head1,size1); 12 | InsertElement(head1,array1); 13 | printf("\nAfter Insert : \n"); 14 | Display(head1); 15 | 16 | printf("After Insertion Sorting :\n"); 17 | sellSort(head1); 18 | Display(head1); 19 | printf("\n\nTest for 4:\n"); 20 | appearsonce(head1,4); 21 | printf("Test for 2:\n"); 22 | appearsonce(head1,2); 23 | 24 | printf("\n\ncount the repeted data : \n"); 25 | appearscount(head1,1); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /All Data Structure/Array Data Structure/Array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ArrayADT.h" 3 | 4 | 5 | int main(){ 6 | struct node *a = NULL; 7 | int size = 4,arr[]={1,2,3,4}; 8 | 9 | a = create(a,size,arr); 10 | printf("\nAfter Create : "); 11 | printArray(a); 12 | 13 | int pos = 2; 14 | delete(a,pos); 15 | printf("\nAfter Delete position %d : ",pos); 16 | printArray(a); 17 | 18 | 19 | insert(a,5); 20 | printf("\nAfter Insert : "); 21 | printArray(a); 22 | 23 | insertPos(a,3,6); 24 | printf("\nAfter InsertPos : "); 25 | printArray(a); 26 | 27 | insertLast(a,3); 28 | printf("\nAfter InsertLast : "); 29 | printArray(a); 30 | 31 | printf("\nLength of array : %d",length(a)); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Assignment-5/Application/Application3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Application3ADT.h" 4 | 5 | int main() 6 | { 7 | struct tree *t=NULL; 8 | int arr[20],k,i,sum=0; 9 | 10 | t=insert(t,29); 11 | insert(t,23); 12 | insert(t,4); 13 | insert(t,13); 14 | insert(t,39); 15 | insert(t,31); 16 | insert(t,45); 17 | insert(t,56); 18 | insert(t,49); 19 | printf("Element in BST : ");inorder(t); 20 | printf("\n\n"); 21 | inorderarray(t,arr); 22 | printf("Enter the no of Elements K : "); 23 | scanf("%d",&k); 24 | printf("\n\n"); 25 | 26 | for(i=0;i 2 | #include 3 | #include "Application2ADT.h" 4 | 5 | int main() 6 | { 7 | struct tree *t1, *t2; 8 | int arr1[10],num1,num2; 9 | 10 | t1=NULL; 11 | t2=NULL; 12 | 13 | t1=insert(t1,29); 14 | insert(t1,23); 15 | insert(t1,4); 16 | insert(t1,13); 17 | insert(t1,39); 18 | insert(t1,31); 19 | insert(t1,45); 20 | insert(t1,56); 21 | insert(t1,49); 22 | 23 | 24 | int x1=inorder(t1,arr1,0); 25 | 26 | printf("Enter the starting Range: "); 27 | scanf("%d",&num1); 28 | printf("Enter the ending Range: "); 29 | scanf("%d",&num2); 30 | 31 | printf("The Elements between %d and %d\n",num1,num2); 32 | count(t1,num1,num2); 33 | printf("\n"); 34 | } 35 | -------------------------------------------------------------------------------- /Assignment 2/polynomial.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "polyABT.h" 5 | 6 | int main() 7 | { 8 | struct Node *poly1 = NULL, *poly2 = NULL, *poly = NULL; 9 | 10 | create_node(6, 7, &poly1); 11 | create_node(8, 3, &poly1); 12 | create_node(7, 2, &poly1); 13 | create_node(9, 0, &poly1); 14 | 15 | create_node(7, 3, &poly2); 16 | create_node(6, 0, &poly2); 17 | 18 | printf("1st Number: "); 19 | display(poly1); 20 | 21 | printf("\n2nd Number: "); 22 | display(poly2); 23 | 24 | poly = (struct Node*)malloc(sizeof(struct Node)); 25 | 26 | polyadd(poly1, poly2, poly); 27 | 28 | printf("\nAdded polynomial: "); 29 | display(poly); 30 | printf("\n\n"); 31 | 32 | return 0; 33 | } 34 | 35 | 36 | 37 | /* 38 | 39 | Poly1: 6x7+8x3 +7x2+9, 40 | Poly2: 7x3+6 41 | Resultant Poly: 6x7+15x3+ 7x2+15 42 | */ 43 | -------------------------------------------------------------------------------- /Assignment-4/queue using array/Queue using array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"qADTa.h" 4 | int main(){ 5 | int de; 6 | struct queue *Q=(struct queue *) malloc(sizeof(struct queue)); 7 | printf("\n"); 8 | printf("\n"); 9 | de =dequeue(Q); 10 | (de==-1)?printf("Empty\n"):printf("Dequeue value : %d \n",de); 11 | createQueue(Q,3); 12 | printf("Inserting : \n"); 13 | enqueue(Q,2); 14 | display(Q); 15 | printf("\n"); 16 | enqueue(Q,13); 17 | display(Q); 18 | printf("\n"); 19 | enqueue(Q,5); 20 | display(Q); 21 | printf("\n"); 22 | de =dequeue(Q); 23 | (de==-1)?printf("Empty\n"):printf("Dequeue value : %d \n",de); 24 | display(Q); 25 | printf("\n"); 26 | de =dequeue(Q); 27 | (de==-1)?printf("Empty\n"):printf("Dequeue value : %d \n",de); 28 | display(Q); 29 | printf("\n"); 30 | printf("\n"); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Assignment-8/application.c: -------------------------------------------------------------------------------- 1 | #include "adt1.h" 2 | void main(){ 3 | struct priorityQueue *PQ; 4 | PQ=(struct priorityQueue *)malloc(sizeof(struct priorityQueue)); 5 | init(PQ,100); 6 | 7 | insert(PQ,'A',15000); 8 | insert(PQ,'K',12000); 9 | insert(PQ,'R',4000); 10 | insert(PQ,'T',3500); 11 | insert(PQ,'L',4600); 12 | insert(PQ,'P',6000); 13 | insert(PQ,'Y',8600); 14 | printf("After Inserting Employees the Max Heap Is\n"); 15 | display(PQ); 16 | printf("After Deleting one Employee the Max Heap Is\n"); 17 | delete(PQ); 18 | display(PQ); 19 | printf("After Deleting one Employee the Max Heap Is\n"); 20 | delete(PQ); 21 | display(PQ); 22 | printf("After Deleting one Employee the Max Heap Is\n"); 23 | delete(PQ); 24 | display(PQ); 25 | printf("After Deleting one Employee the Max Heap Is\n"); 26 | delete(PQ); 27 | display(PQ); 28 | 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /Assignment-8/basic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "adt.h" 5 | 6 | void main(){ 7 | struct priorityQueue *PQ; 8 | PQ=(struct priorityQueue *)malloc(sizeof(struct priorityQueue)); 9 | init(PQ,100); 10 | insert(PQ,14); 11 | insert(PQ,16); 12 | insert(PQ,22); 13 | insert(PQ,11); 14 | insert(PQ,9); 15 | insert(PQ,18); 16 | insert(PQ,10); 17 | insert(PQ,7); 18 | insert(PQ,4); 19 | insert(PQ,1); 20 | printf("After Inserting The Elements : \n"); 21 | displayb(PQ); 22 | printf("After Deleting one Element : \n"); 23 | delete(PQ); 24 | displayb(PQ); 25 | printf("After Deleting one Element :\n"); 26 | delete(PQ); 27 | displayb(PQ); 28 | printf("After Deleting one Element :\n"); 29 | delete(PQ); 30 | displayb(PQ); 31 | printf("After Deleting one Element : \n"); 32 | delete(PQ); 33 | displayb(PQ); 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /Assignment-11/sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "arrADT.h" 4 | #include "SellsortADT.h" 5 | 6 | int main() 7 | { 8 | // Insertion Sorting 9 | struct node *head; 10 | int array[]= {2,6,8,10,1,3},size=6; 11 | head = (struct node*) malloc(sizeof(struct node)); 12 | 13 | initI(head,size); 14 | InsertElementI(head,array); 15 | printf("\nAfter Create : \n"); 16 | DisplayI(head); 17 | 18 | printf("After Insertion Sorting :\n"); 19 | InsSort(head); 20 | DisplayI(head); 21 | 22 | struct node1 *head1; 23 | int array1[]= {347,27,298,188,28,385},size1=6; 24 | head1 = (struct node1*) malloc(sizeof(struct node1)); 25 | 26 | init(head1,size1); 27 | InsertElement(head1,array1); 28 | printf("\nAfter Create : \n"); 29 | Display(head1); 30 | 31 | printf("After Sell Sorting :\n"); 32 | sellSort(head1); 33 | Display(head1); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Assignment-4/queue using array/qADTa.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct queue{ 4 | int arr[3]; 5 | int size; 6 | int f,r; 7 | }; 8 | 9 | void createQueue(struct queue *Q,int lim){ 10 | Q->size = lim; 11 | Q->f = -1; 12 | Q->r = -1; 13 | } 14 | 15 | void enqueue( struct queue *Q, int info){ 16 | if (isFill(Q)) 17 | printf("full"); 18 | else{ 19 | Q->r++; 20 | Q->arr[Q->r] = info; 21 | } 22 | } 23 | 24 | int isFill(struct queue *Q){ 25 | if(Q->r == Q->size-1) 26 | return 1; 27 | else return 0; 28 | } 29 | 30 | int dequeue(struct queue *Q){ 31 | if(isEmpty(Q)) 32 | return -1; 33 | else{ 34 | Q->f++; 35 | return Q->arr[Q->f]; 36 | } 37 | } 38 | 39 | int isEmpty(struct queue *Q){ 40 | if(Q->f == Q->r) 41 | return 1; 42 | else return 0; 43 | } 44 | 45 | void display(struct queue *Q){ 46 | for(int i=Q->f+1; ir+1; i++) 47 | printf("%d ",Q->arr[i]); 48 | } 49 | -------------------------------------------------------------------------------- /Assignment-6/Application/Application2.c: -------------------------------------------------------------------------------- 1 | #include"Application2ADT.h" 2 | 3 | void main() { 4 | int result; 5 | struct node *h,*ptr1,*ptr2; 6 | h = (struct node *)malloc(sizeof(struct node)); 7 | ptr1=(struct node *)malloc(sizeof(struct node)); 8 | ptr2=(struct node *)malloc(sizeof(struct node)); 9 | 10 | insertFront(h,'D'); // DATASTRUCTURE 11 | insertFront(h,'A'); 12 | insertFront(h,'T'); 13 | insertFront(h,'A'); 14 | insertFront(h,'S'); 15 | insertFront(h,'T'); 16 | insertFront(h,'R'); 17 | insertFront(h,'U'); 18 | insertFront(h,'C'); 19 | insertFront(h,'T'); 20 | insertFront(h,'U'); 21 | insertFront(h,'R'); 22 | insertFront(h,'E'); 23 | 24 | displayItems(h); 25 | 26 | printf("\n"); 27 | 28 | seperate(h,ptr1,ptr2); 29 | 30 | displayItems(ptr1); 31 | printf("\n"); 32 | displayItems(ptr2); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Assignment-11/arrADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int *arr; 6 | int size; 7 | }; 8 | 9 | void initI(struct node *a, int siz) 10 | { 11 | a->size = siz; 12 | a->arr = (int*) malloc(siz*(2+1) *sizeof(int)); 13 | } 14 | 15 | void InsertElementI(struct node *a, int *array){ 16 | int i; 17 | a->arr[0] = -99; 18 | for(i=1; isize; i++){ 19 | a->arr[i] = array[i]; 20 | } 21 | } 22 | 23 | void DisplayI(struct node *a){ 24 | printf("Array Element : "); 25 | for(int i=1; isize; i++){ 26 | printf("%d ",a->arr[i]); 27 | } 28 | printf("\n\n"); 29 | } 30 | 31 | void InsSort(struct node *a){ 32 | 33 | int i; 34 | for(i=2; isize; i++){ 35 | int j = i; 36 | while(a->arr[j] < a->arr[j-1]){ 37 | int temp = a->arr[j-1]; 38 | a->arr[j-1] = a->arr[j]; 39 | a->arr[j] = temp; 40 | j = j-1; 41 | } 42 | } 43 | 44 | } 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Assignment-3/PostfixApplicationADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct stack 6 | { 7 | char a[100]; 8 | int size; 9 | int top; 10 | }; 11 | 12 | void createStack(struct stack *s,int size) 13 | { 14 | s->size=size; 15 | s->top=-1; 16 | } 17 | 18 | 19 | int isEmpty(struct stack *s) 20 | { 21 | if(s->top==-1) 22 | return 1; 23 | else 24 | return 0; 25 | } 26 | 27 | int isFull(struct stack *s) 28 | { 29 | if(s->top==s->size-1) 30 | return 1; 31 | else 32 | return 0; 33 | } 34 | 35 | void push(struct stack *s,char x) 36 | { 37 | if(isFull(s)) 38 | printf("Stack is full\n"); 39 | else 40 | { 41 | s->top++; 42 | s->a[s->top]=x; 43 | } 44 | } 45 | 46 | int pop(struct stack *s) 47 | { 48 | if(s->top!=-1) 49 | return s->a[s->top--]; 50 | } 51 | 52 | void display(struct stack *s) 53 | { 54 | int t=s->top; 55 | while(s->top!=-1) 56 | { 57 | printf("%d,",s->a[s->top]); 58 | s->top--; 59 | } 60 | s->top=t; 61 | printf("\n"); 62 | } 63 | -------------------------------------------------------------------------------- /Assignment 1/arrADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int *arr; 6 | int size; 7 | }; 8 | 9 | void create(struct node *str, int siz, int *array){ 10 | int i; 11 | str->size = siz; 12 | str->arr = (int*) malloc(siz*(2+1) *sizeof(int)); 13 | for(i=0; isize; i++){ 14 | str->arr[i] = array[i]; 15 | } 16 | } 17 | 18 | void printArray(struct node *str){ 19 | int i; 20 | for(i=0; isize; i++){ 21 | printf("%d ",str->arr[i]); 22 | } 23 | } 24 | 25 | void deleteAt(struct node *str, int pos ){ 26 | int i; 27 | for(i=pos; isize; i++){ 28 | str->arr[i] = str->arr[i+1]; 29 | } 30 | --str->size; 31 | 32 | } 33 | 34 | void insertAtEvery(struct node *str, int key){ 35 | int i,temp = str->size; 36 | temp--; 37 | str->size *=2; 38 | for(i=str->size-1; i>=0; i-=2){ 39 | str->arr[i] = str->arr[temp]; 40 | temp--; 41 | str->arr[i-1] = key; 42 | } 43 | } 44 | 45 | 46 | int search(struct node *str, int key){ 47 | return str->arr[key]; 48 | } 49 | -------------------------------------------------------------------------------- /Assignment-3/Stack.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "ADT.h" 5 | 6 | 7 | int main(){ 8 | struct stack *top = (struct stack*) malloc(sizeof(struct stack)); 9 | createStack(top, 10); 10 | (gettop(top)==-1)?printf("Gettop : Empty\n"):printf("Gettop : %d\n",gettop(top)); 11 | push(top,4); 12 | printf("\nAfter push : ");display(top); 13 | push(top,6); 14 | printf("\nAfter push : ");display(top); 15 | push(top,8); 16 | printf("\nAfter push : ");display(top); 17 | pop(top); 18 | (gettop(top)==-1)?printf("\nGettop : Empty\n"):printf("\nGettop : %d\n",gettop(top)); 19 | (gettop(top)==-1)?printf("\nGettop : Empty\n"):printf("\nGettop : %d\n",gettop(top)); 20 | pop(top); 21 | pop(top); 22 | (gettop(top)==-1)?printf("Gettop : Empty\n"):printf("Gettop : %d\n",gettop(top)); 23 | pop(top); 24 | pop(top); 25 | printf("\nAfter push : ");display(top); 26 | (gettop(top)==-1)?printf("\nGettop : Empty\n"):printf("\nGettop : %d\n",gettop(top)); 27 | 28 | return 0; 29 | 30 | 31 | 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /Assignment-9/Queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct queue{ 4 | int *arr; 5 | int size; 6 | int f,r; 7 | }; 8 | 9 | int isEmpty(struct queue *Q){ 10 | if(Q->f == Q->r) 11 | return 1; 12 | else return 0; 13 | } 14 | 15 | int isFill(struct queue *Q){ 16 | if(Q->r == Q->size-1) 17 | return 1; 18 | else return 0; 19 | } 20 | 21 | 22 | struct queue * createQueue(int lim){ 23 | struct queue *Q=(struct queue *) malloc(sizeof(struct queue)); 24 | Q->arr = (int *) malloc(lim * sizeof(int)); 25 | Q->size = lim; 26 | Q->f = -1; 27 | Q->r = -1; 28 | } 29 | 30 | void enqueue( struct queue *Q, int info){ 31 | if (isFill(Q)) 32 | printf("full"); 33 | else{ 34 | Q->r++; 35 | Q->arr[Q->r] = info; 36 | } 37 | } 38 | 39 | 40 | int dequeue(struct queue *Q){ 41 | if(isEmpty(Q)) 42 | return -1; 43 | else{ 44 | Q->f++; 45 | return Q->arr[Q->f]; 46 | } 47 | } 48 | 49 | 50 | void display(struct queue *Q){ 51 | printf("\n"); 52 | for(int i=Q->f+1; ir+1; i++) 53 | printf("%d ",Q->arr[i]); 54 | } -------------------------------------------------------------------------------- /All Data Structure/GRAPH/Queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct queue{ 4 | int *arr; 5 | int size; 6 | int f,r; 7 | }; 8 | 9 | int isEmpty(struct queue *Q){ 10 | if(Q->f == Q->r) 11 | return 1; 12 | else return 0; 13 | } 14 | 15 | int isFill(struct queue *Q){ 16 | if(Q->r == Q->size-1) 17 | return 1; 18 | else return 0; 19 | } 20 | 21 | 22 | struct queue * createQueue(int lim){ 23 | struct queue *Q=(struct queue *) malloc(sizeof(struct queue)); 24 | Q->arr = (int *) malloc(lim * sizeof(int)); 25 | Q->size = lim; 26 | Q->f = -1; 27 | Q->r = -1; 28 | } 29 | 30 | void enqueue( struct queue *Q, int info){ 31 | if (isFill(Q)) 32 | printf("full"); 33 | else{ 34 | Q->r++; 35 | Q->arr[Q->r] = info; 36 | } 37 | } 38 | 39 | 40 | int dequeue(struct queue *Q){ 41 | if(isEmpty(Q)) 42 | return -1; 43 | else{ 44 | Q->f++; 45 | return Q->arr[Q->f]; 46 | } 47 | } 48 | 49 | 50 | void display(struct queue *Q){ 51 | printf("\n"); 52 | for(int i=Q->f+1; ir+1; i++) 53 | printf("%d ",Q->arr[i]); 54 | } -------------------------------------------------------------------------------- /Assignment-9/Application/Queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct queue{ 4 | int *arr; 5 | int size; 6 | int f,r; 7 | }; 8 | 9 | int isEmpty(struct queue *Q){ 10 | if(Q->f == Q->r) 11 | return 1; 12 | else return 0; 13 | } 14 | 15 | int isFill(struct queue *Q){ 16 | if(Q->r == Q->size-1) 17 | return 1; 18 | else return 0; 19 | } 20 | 21 | 22 | struct queue * createQueue(int lim){ 23 | struct queue *Q=(struct queue *) malloc(sizeof(struct queue)); 24 | Q->arr = (int *) malloc(lim * sizeof(int)); 25 | Q->size = lim; 26 | Q->f = -1; 27 | Q->r = -1; 28 | } 29 | 30 | void enqueue( struct queue *Q, int info){ 31 | if (isFill(Q)) 32 | printf("full"); 33 | else{ 34 | Q->r++; 35 | Q->arr[Q->r] = info; 36 | } 37 | } 38 | 39 | 40 | int dequeue(struct queue *Q){ 41 | if(isEmpty(Q)) 42 | return -1; 43 | else{ 44 | Q->f++; 45 | return Q->arr[Q->f]; 46 | } 47 | } 48 | 49 | 50 | void display(struct queue *Q){ 51 | printf("\n"); 52 | for(int i=Q->f+1; ir+1; i++) 53 | printf("%d ",Q->arr[i]); 54 | } -------------------------------------------------------------------------------- /All Data Structure/Queue using array implementation/Queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct queue{ 4 | int *arr; 5 | int size; 6 | int f,r; 7 | }; 8 | 9 | int isEmpty(struct queue *Q){ 10 | if(Q->f == Q->r) 11 | return 1; 12 | else return 0; 13 | } 14 | 15 | int isFill(struct queue *Q){ 16 | if(Q->r == Q->size-1) 17 | return 1; 18 | else return 0; 19 | } 20 | 21 | 22 | struct queue * createQueue(int lim){ 23 | struct queue *Q=(struct queue *) malloc(sizeof(struct queue)); 24 | Q->arr = (int *) malloc(lim * sizeof(int)); 25 | Q->size = lim; 26 | Q->f = -1; 27 | Q->r = -1; 28 | } 29 | 30 | void enqueue( struct queue *Q, int info){ 31 | if (isFill(Q)) 32 | printf("full"); 33 | else{ 34 | Q->r++; 35 | Q->arr[Q->r] = info; 36 | } 37 | } 38 | 39 | 40 | int dequeue(struct queue *Q){ 41 | if(isEmpty(Q)) 42 | return -1; 43 | else{ 44 | Q->f++; 45 | return Q->arr[Q->f]; 46 | } 47 | } 48 | 49 | 50 | void display(struct queue *Q){ 51 | printf("\n"); 52 | for(int i=Q->f+1; ir+1; i++) 53 | printf("%d ",Q->arr[i]); 54 | } -------------------------------------------------------------------------------- /Assignment 2/LINKEDLIST.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"ABT.h" 4 | int main() 5 | { 6 | struct node *header,*sea; 7 | int temp; 8 | header = (struct node*) malloc( sizeof(struct node)); 9 | header->next = NULL; 10 | 11 | 12 | 13 | 14 | printf("\nlength = %d\n",length(header)); 15 | printf("Insert elements : "); 16 | insert(header,2);printf("\n"); 17 | display(header); 18 | insert(header,4);printf("\n"); 19 | display(header); 20 | insert(header,6);printf("\n"); 21 | display(header); 22 | insert(header,8);printf("\n"); 23 | display(header); 24 | 25 | printf("\nlength = %d\n",length(header)); 26 | 27 | temp = middle(header); 28 | printf("middle value = %d\n",temp); 29 | 30 | temp = search(header,4); 31 | printf("\nsearch result = %d\n",temp); 32 | temp = search(header,5); 33 | printf("\nsearch result = %d\n",temp); 34 | 35 | delet(header,2); 36 | printf("\nAfter Delete : "); 37 | display(header); 38 | reverseList(header); 39 | printf("\nAfter Reverse : "); 40 | display(header); 41 | printf("\n\n"); 42 | 43 | return 0; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Assignment-5/Application/Application1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Application1ADT.h" 4 | 5 | int main() 6 | { 7 | struct tree *t1, *t2; 8 | int arr1[10],count=0,i,sum=0; 9 | int arr2[10]; 10 | 11 | t1=NULL; 12 | t2=NULL; 13 | 14 | t1=insert(t1,29); 15 | insert(t1,23); 16 | insert(t1,4); 17 | insert(t1,13); 18 | insert(t1,39); 19 | insert(t1,31); 20 | insert(t1,45); 21 | insert(t1,56); 22 | insert(t1,49); 23 | 24 | t2=insert(t2,29); 25 | insert(t2,23); 26 | insert(t2,4); 27 | insert(t2,13); 28 | insert(t2,39); 29 | insert(t2,31); 30 | insert(t2,45); 31 | insert(t2,56); 32 | insert(t2,49); 33 | printf("\nTree 1 :"); 34 | inorder(t1); 35 | printf("\nTree 2 :"); 36 | inorder(t2); 37 | int x1=inorderarray(t1,arr1,0); 38 | int x2=inorderarray(t2,arr2,0); 39 | 40 | for(i=0;i 2 | #include 3 | #include "ADT.h" 4 | 5 | int main() 6 | { 7 | struct tree *t,*max,*min,*sea; 8 | max=(struct tree*)malloc(sizeof(struct tree*)); 9 | min=(struct tree*)malloc(sizeof(struct tree*)); 10 | t=NULL; 11 | t=insert(t,29); 12 | insert(t,23); 13 | insert(t,4); 14 | insert(t,13); 15 | insert(t,39); 16 | insert(t,31); 17 | insert(t,45); 18 | insert(t,56); 19 | insert(t,49); 20 | printf("INORDER :"); 21 | inorder(t); 22 | printf("\nPREORDER :"); 23 | preorder(t); 24 | printf("\nPOSTORDER :"); 25 | postorder(t); 26 | max=findMax(t); 27 | printf("\nMax Value is: %d",max->data); 28 | min=findMin(t); 29 | printf("\nMin value is: %d",min->data); 30 | sea=search(t,39); 31 | if(sea!=NULL){ 32 | printf("\nThe element is found, value is %d",sea->data); 33 | } 34 | else{ 35 | printf("\nThe element is not found"); 36 | } 37 | t=delete(t,4); 38 | printf("\nINORDER: "); 39 | inorder(t); 40 | } 41 | -------------------------------------------------------------------------------- /Assignment-11/SellsortADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node1 { 5 | int *arr; 6 | int size; 7 | }; 8 | 9 | void init(struct node1 *a, int siz) 10 | { 11 | a->size = siz; 12 | a->arr = (int*) malloc(siz*(2+1) *sizeof(int)); 13 | } 14 | 15 | void InsertElement(struct node1 *a, int *array){ 16 | int i; 17 | //a->arr[0] = -99; 18 | for(i=0; isize; i++){ 19 | a->arr[i] = array[i]; 20 | } 21 | } 22 | 23 | void Display(struct node1 *a){ 24 | printf("Array Element : "); 25 | for(int i=0; isize; i++){ 26 | printf("%d ",a->arr[i]); 27 | } 28 | printf("\n\n"); 29 | } 30 | 31 | 32 | void sellSort(struct node1 *a) 33 | 34 | { 35 | for (int i = a->size / 2; i > 0; i = i / 2){ 36 | for (int j = i; j < a->size; j++){ 37 | for(int k = j - i; k >= 0; k = k - i){ 38 | if (a->arr[k+i] >= a->arr[k]){ 39 | break; 40 | } 41 | else 42 | { 43 | int temp = a->arr[k]; 44 | a->arr[k] = a->arr[k+i]; 45 | a->arr[k+i] = temp; 46 | 47 | } 48 | } 49 | } 50 | } 51 | return ; 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Assignment-5/Application/Application1ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct tree{ 5 | int data; 6 | struct tree *left; 7 | struct tree *right; 8 | }; 9 | struct tree *insert(struct tree *t,int x) 10 | { 11 | if (t==NULL) 12 | { 13 | t=(struct tree*)malloc(sizeof(struct tree)); 14 | t->data=x; 15 | t->left=NULL; 16 | t->right=NULL; 17 | } 18 | else if(x>t->data) 19 | { 20 | t->right=insert(t->right,x); 21 | } 22 | else 23 | { 24 | t->left=insert(t->left,x); 25 | } 26 | return t; 27 | } 28 | int inorderarray(struct tree *t,int arr[],int i) 29 | { 30 | if (t->left!=NULL){ 31 | inorderarray(t->left,arr,i++); 32 | } 33 | arr[i++]=t->data; 34 | if(t->right!=NULL){ 35 | inorderarray(t->right,arr,i++); 36 | } 37 | return i; 38 | } 39 | 40 | 41 | void inorder(struct tree *t) 42 | { 43 | if (t->left!=NULL){ 44 | inorder(t->left); 45 | } 46 | printf("%d,",t->data); 47 | if(t->right!=NULL){ 48 | inorder(t->right); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assignment-5/Application/Application3ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct tree{ 5 | int data; 6 | struct tree *left; 7 | struct tree *right; 8 | }; 9 | struct tree *insert(struct tree *t,int x) 10 | { 11 | if (t==NULL) 12 | { 13 | t=(struct tree*)malloc(sizeof(struct tree)); 14 | t->data=x; 15 | t->left=NULL; 16 | t->right=NULL; 17 | } 18 | else if(x>t->data) 19 | { 20 | t->right=insert(t->right,x); 21 | } 22 | else 23 | { 24 | t->left=insert(t->left,x); 25 | } 26 | return t; 27 | } 28 | void inorderarray(struct tree *t,int arr[]) 29 | { 30 | static int i=0; 31 | if (t->left!=NULL){ 32 | inorderarray(t->left,arr); 33 | } 34 | arr[i++]=t->data; 35 | if(t->right!=NULL){ 36 | inorderarray(t->right,arr); 37 | } 38 | } 39 | 40 | 41 | 42 | void inorder(struct tree *t) 43 | { 44 | if (t->left!=NULL){ 45 | inorder(t->left); 46 | } 47 | printf("%d,",t->data); 48 | if(t->right!=NULL){ 49 | inorder(t->right); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Assignment-9/Stack.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct stack { 5 | int arr[100]; 6 | int size,top; 7 | }; 8 | int isEmptystack(struct stack *S){ 9 | if(S->top == -1) return 1; 10 | else return 0; 11 | } 12 | 13 | 14 | int isFillstack(struct stack *S){ 15 | if(S->top == S->size-1) 16 | return 1; 17 | return 0; 18 | } 19 | 20 | int gettop(struct stack *S){ 21 | if(isEmptystack(S)) 22 | return -1; 23 | else return S->arr[S->top]; 24 | } 25 | 26 | 27 | struct stack * createStack(int lim) 28 | { 29 | struct stack *s = (struct stack *) malloc(sizeof(struct stack)); 30 | s->size = lim; 31 | s->top = -1; 32 | return s; 33 | } 34 | 35 | void push(struct stack *S, int x) 36 | { 37 | if(isFillstack(S)){ 38 | printf("FULL"); 39 | return ; 40 | } 41 | S->top++; 42 | S->arr[S->top] = x; 43 | 44 | } 45 | 46 | 47 | void displayStack(struct stack *S) 48 | { 49 | struct stack *ptr=S; 50 | for(int i=0; itop+1; i++){ 51 | printf("%d ",ptr->arr[i]); 52 | } 53 | 54 | } 55 | 56 | 57 | void pop (struct stack *S) 58 | { 59 | if(isEmptystack(S) == 1) 60 | return ; 61 | S->top--; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Assignment-5/Application/Application2ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct tree{ 5 | int data; 6 | struct tree *left; 7 | struct tree *right; 8 | }; 9 | struct tree *insert(struct tree *t,int x) 10 | { 11 | if (t==NULL) 12 | { 13 | t=(struct tree*)malloc(sizeof(struct tree)); 14 | t->data=x; 15 | t->left=NULL; 16 | t->right=NULL; 17 | } 18 | else if(x>t->data) 19 | { 20 | t->right=insert(t->right,x); 21 | } 22 | else 23 | { 24 | t->left=insert(t->left,x); 25 | } 26 | return t; 27 | } 28 | int inorder(struct tree *t,int arr[],int i) 29 | { 30 | if (t->left!=NULL){ 31 | inorder(t->left,arr,i++); 32 | } 33 | arr[i++]=t->data; 34 | if(t->right!=NULL){ 35 | inorder(t->right,arr,i++); 36 | } 37 | return i; 38 | } 39 | 40 | void count(struct tree *t, int a, int b) { 41 | if(t->left!=NULL) 42 | count(t->left, a, b); 43 | if(t->data > a && t->data < b) 44 | printf("%d ", t->data); 45 | if(t->right!=NULL) 46 | count(t->right, a, b); 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /All Data Structure/GRAPH/Stack.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct stack { 5 | int arr[100]; 6 | int size,top; 7 | }; 8 | int isEmptystack(struct stack *S){ 9 | if(S->top == -1) return 1; 10 | else return 0; 11 | } 12 | 13 | 14 | int isFillstack(struct stack *S){ 15 | if(S->top == S->size-1) 16 | return 1; 17 | return 0; 18 | } 19 | 20 | int gettop(struct stack *S){ 21 | if(isEmptystack(S)) 22 | return -1; 23 | else return S->arr[S->top]; 24 | } 25 | 26 | 27 | struct stack * createStack(int lim) 28 | { 29 | struct stack *s = (struct stack *) malloc(sizeof(struct stack)); 30 | s->size = lim; 31 | s->top = -1; 32 | return s; 33 | } 34 | 35 | void push(struct stack *S, int x) 36 | { 37 | if(isFillstack(S)){ 38 | printf("FULL"); 39 | return ; 40 | } 41 | S->top++; 42 | S->arr[S->top] = x; 43 | 44 | } 45 | 46 | 47 | void displayStack(struct stack *S) 48 | { 49 | struct stack *ptr=S; 50 | for(int i=0; itop+1; i++){ 51 | printf("%d ",ptr->arr[i]); 52 | } 53 | 54 | } 55 | 56 | 57 | void pop (struct stack *S) 58 | { 59 | if(isEmptystack(S) == 1) 60 | return ; 61 | S->top--; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Assignment-10/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dijsktrasgraph.h" 4 | 5 | 6 | int main() 7 | { 8 | struct graph *g = create_graph(); 9 | int start; 10 | printf("Enter the starting point : "); 11 | scanf("%d",&start); 12 | int **table = dijkstra(g, start-1); 13 | 14 | printf("\tFinal Tablie :-\n"); 15 | displayTable(g,table); 16 | 17 | // printf("\n Table Structure\n"); 18 | // for (int i = 0; i < g->vertex; i++) 19 | // printf(" %d ---> %d --> %d\n",table[0][i],table[1][i],table[2][i]); 20 | 21 | printf("Enter the Destination point : "); 22 | scanf("%d",&start); 23 | start--; 24 | printf("\n\n\tPath Printing for %s \n",g->data[start]); 25 | printPath(g,table,start); 26 | printf("\n\n"); 27 | return 0; 28 | } 29 | 30 | 31 | 32 | /* 33 | Test case 1 34 | 7 12 35 | 1 4 1 36 | 1 2 2 37 | 2 4 3 38 | 2 5 10 39 | 5 7 6 40 | 7 6 1 41 | 3 1 4 42 | 3 6 5 43 | 4 3 2 44 | 4 5 2 45 | 4 7 4 46 | 4 6 8 47 | v1 48 | v2 49 | v3 50 | v4 51 | v5 52 | v6 53 | v7 54 | 55 | 7 6 56 | 1 2 1 57 | 1 3 1 58 | 3 4 1 59 | 4 5 1 60 | 5 6 1 61 | 7 2 1 62 | A 63 | B 64 | C 65 | D 66 | E 67 | F 68 | G 69 | 70 | 71 | */ 72 | -------------------------------------------------------------------------------- /Assignment-9/Application/Stack.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct stack { 5 | int arr[100]; 6 | int size,top; 7 | }; 8 | int isEmptystack(struct stack *S){ 9 | if(S->top == -1) return 1; 10 | else return 0; 11 | } 12 | 13 | 14 | int isFillstack(struct stack *S){ 15 | if(S->top == S->size-1) 16 | return 1; 17 | return 0; 18 | } 19 | 20 | int gettop(struct stack *S){ 21 | if(isEmptystack(S)) 22 | return -1; 23 | else return S->arr[S->top]; 24 | } 25 | 26 | 27 | struct stack * createStack(int lim) 28 | { 29 | struct stack *s = (struct stack *) malloc(sizeof(struct stack)); 30 | s->size = lim; 31 | s->top = -1; 32 | return s; 33 | } 34 | 35 | void push(struct stack *S, int x) 36 | { 37 | if(isFillstack(S)){ 38 | printf("FULL"); 39 | return ; 40 | } 41 | S->top++; 42 | S->arr[S->top] = x; 43 | 44 | } 45 | 46 | 47 | void displayStack(struct stack *S) 48 | { 49 | struct stack *ptr=S; 50 | for(int i=0; itop+1; i++){ 51 | printf("%d ",ptr->arr[i]); 52 | } 53 | 54 | } 55 | 56 | 57 | void pop (struct stack *S) 58 | { 59 | if(isEmptystack(S) == 1) 60 | return ; 61 | S->top--; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /All Data Structure/Stack using array implementation/StackADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct stack { 5 | int arr[100]; 6 | int size,top; 7 | }; 8 | int isEmpty(struct stack *S){ 9 | if(S->top == -1) return 1; 10 | else return 0; 11 | } 12 | 13 | 14 | int isFill(struct stack *S){ 15 | if(S->top == S->size-1) 16 | return 1; 17 | return 0; 18 | } 19 | 20 | int gettop(struct stack *S){ 21 | if(isEmpty(S)) 22 | return -1; 23 | else return S->arr[S->top]; 24 | } 25 | 26 | 27 | struct stack * createStack(int lim) 28 | { 29 | struct stack *s = (struct stack *) malloc(sizeof(struct stack)); 30 | s->size = lim; 31 | s->top = -1; 32 | return s; 33 | } 34 | 35 | void push(struct stack *S, int x) 36 | { 37 | if(isFill(S)){ 38 | printf("FULL"); 39 | return ; 40 | } 41 | S->top++; 42 | S->arr[S->top] = x; 43 | 44 | } 45 | 46 | 47 | void displayStack(struct stack *S) 48 | { 49 | struct stack *ptr=S; 50 | for(int i=0; itop+1; i++){ 51 | printf("%d ",ptr->arr[i]); 52 | } 53 | 54 | } 55 | 56 | 57 | void pop (struct stack *S) 58 | { 59 | if(isEmpty(S) == 1) 60 | return ; 61 | S->top--; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Assignment-6/Application/Application1.c: -------------------------------------------------------------------------------- 1 | #include"Application1ADT.h" 2 | 3 | void main() { 4 | int result; 5 | struct node *h; 6 | h = (struct node *)malloc(sizeof(struct node)); 7 | 8 | insertFront(h,'M'); // MALAYALAM 9 | insertFront(h,'A'); 10 | insertFront(h,'L'); 11 | insertFront(h,'A'); 12 | insertFront(h,'Y'); 13 | insertFront(h,'A'); 14 | insertFront(h,'L'); 15 | insertFront(h,'A'); 16 | insertFront(h,'M'); 17 | 18 | displayItems(h); 19 | 20 | printf("\n"); 21 | 22 | result=isPalindrome(h); 23 | 24 | if(result==1) 25 | printf("The given list is Palindrome\n"); 26 | else 27 | printf("The given list is not Palindrome\n"); 28 | 29 | 30 | struct node *h1; 31 | h1 = (struct node *)malloc(sizeof(struct node)); 32 | 33 | insertFront(h1,'D'); // DATA 34 | insertFront(h1,'A'); 35 | insertFront(h1,'T'); 36 | insertFront(h1,'A'); 37 | displayItems(h1); 38 | 39 | printf("\n"); 40 | 41 | result=isPalindrome(h1); 42 | 43 | if(result==1) 44 | printf("The given list is Palindrome\n"); 45 | else 46 | printf("The given list is not Palindrome\n"); 47 | } 48 | -------------------------------------------------------------------------------- /Assignment 1/A1_8.c: -------------------------------------------------------------------------------- 1 | /* 2 | 8. Insert, Edit and Delete the contents of student data using structure, function, and pointers 3 | */ 4 | #include 5 | #include 6 | #include 7 | struct student{ 8 | char Name[30]; 9 | int regno; 10 | }; 11 | 12 | void Edit(struct student *ptr, int regno, char *name); 13 | void Insert(struct student *ptr, int regno, char *name); 14 | void Delete(struct student *ptr); 15 | void Edit(struct student *ptr, int regno, char *name) 16 | { 17 | ptr->regno = regno; 18 | strcpy(ptr->Name,name); 19 | } 20 | 21 | void Delete(struct student *ptr) 22 | { 23 | free(ptr); 24 | } 25 | 26 | void Insert(struct student *ptr, int regno, char *name){ 27 | ptr->regno = regno; 28 | strcpy(ptr->Name,name); 29 | } 30 | void main() 31 | { 32 | struct student *ptr = (struct student*) malloc(sizeof(struct student)); 33 | 34 | Insert(ptr,18,"sugumar"); 35 | printf("student regester No = %d \n",ptr->regno); 36 | printf("student Name = %s \n",ptr->Name); 37 | 38 | Edit(ptr,19,"murugan"); 39 | printf("student regester No = %d \n",ptr->regno); 40 | printf("student Name = %s \n",ptr->Name); 41 | 42 | Delete(ptr); 43 | printf("student regester No = %d \n",ptr->regno); 44 | printf("student Name = %s \n",ptr->Name); 45 | 46 | return ; 47 | } 48 | -------------------------------------------------------------------------------- /All Data Structure/BST/queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct tree{ 5 | int data; 6 | struct tree *left, *right; 7 | }; 8 | 9 | struct queue{ 10 | struct tree **arr; 11 | int size; 12 | int f,r; 13 | }; 14 | 15 | int isEmpty(struct queue *Q){ 16 | if(Q->f == Q->r) 17 | return 1; 18 | else return 0; 19 | } 20 | 21 | int isFill(struct queue *Q){ 22 | if(Q->r == Q->size-1) 23 | return 1; 24 | else return 0; 25 | } 26 | 27 | 28 | struct queue * createQueue(int lim){ 29 | struct queue *Q=(struct queue *) malloc(sizeof(struct queue)); 30 | Q->arr = (struct tree **) malloc( lim * sizeof(struct tree)); 31 | Q->size = lim; 32 | Q->f = -1; 33 | Q->r = -1; 34 | return Q; 35 | } 36 | 37 | void enqueue( struct queue *Q, struct tree * info){ 38 | if (isFill(Q)) 39 | printf("full"); 40 | else{ 41 | Q->r++; 42 | Q->arr[Q->r] = info; 43 | } 44 | } 45 | 46 | 47 | void dequeue(struct queue *Q){ 48 | if(isEmpty(Q)) 49 | return ; 50 | else{ 51 | Q->f++; 52 | } 53 | } 54 | 55 | 56 | void display(struct queue *Q){ 57 | printf("\n"); 58 | for(int i=Q->f+1; ir+1; i++) 59 | printf("%d ",Q->arr[i]->data); 60 | } 61 | 62 | struct tree * peek(struct queue *q){ 63 | if(isEmpty(q)) return NULL; 64 | else return q->arr[q->r]; 65 | } 66 | -------------------------------------------------------------------------------- /Assignment-6/ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct node { 6 | char data; 7 | struct node *lptr, *rptr; 8 | }; 9 | 10 | void insertFront(struct node *h, char c) { 11 | struct node *temp, *ptr; 12 | temp = (struct node *)malloc(sizeof(struct node)); 13 | temp->data = c; 14 | ptr = h->rptr; 15 | temp->rptr = ptr; 16 | h->rptr = temp; 17 | temp->lptr = h; 18 | if(ptr!=NULL) ptr->lptr = temp; 19 | } 20 | 21 | void insertLast(struct node *h, char c) { 22 | struct node *temp, *ptr=h; 23 | temp = (struct node *)malloc(sizeof(struct node)); 24 | temp->data = c; 25 | while(ptr->rptr != NULL) 26 | ptr = ptr->rptr; 27 | temp->rptr = ptr->rptr; 28 | temp->lptr = ptr; 29 | ptr->rptr = temp; 30 | } 31 | 32 | 33 | void displayItems(struct node *h) { 34 | struct node *ptr, *prev; 35 | ptr = h->rptr; 36 | prev = h; 37 | printf("Double Linked list in Forward\n"); 38 | while(ptr!=NULL) { 39 | printf("%c ", ptr->data); 40 | prev = ptr; 41 | ptr = ptr->rptr; 42 | } 43 | printf("\n"); 44 | printf("Double Linked list in backward\n"); 45 | while(prev!=h) { 46 | printf("%c ", prev->data); 47 | prev = prev->lptr; 48 | } 49 | printf("\n"); 50 | } 51 | -------------------------------------------------------------------------------- /All Data Structure/Array Data Structure/ArrayADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | struct node{ 6 | int size; 7 | int *arr; 8 | }; 9 | 10 | struct node * create(struct node *a,int size, int array[]){ 11 | struct node *temp = (struct node*) malloc(sizeof(struct node)); 12 | temp->size = size; 13 | temp->arr = (int *) malloc((temp->size+5) * sizeof(int)); 14 | int i; 15 | for(i=0; iarr[i] = array[i]; 17 | } 18 | return temp; 19 | } 20 | 21 | void delete(struct node *a, int pos){ 22 | int i; 23 | for(i=pos-1; isize; i++){ 24 | a->arr[i] = a->arr[i+1]; 25 | } 26 | a->size--; 27 | } 28 | 29 | void printArray(struct node *a){ 30 | int i; 31 | for(i=0; i < a->size; i++){ 32 | printf("%d ",a->arr[i]); 33 | } 34 | 35 | } 36 | 37 | void insert(struct node *a, int x){ 38 | int i; 39 | for(i=a->size; i>=0; i--){ 40 | a->arr[i] = a->arr[i-1]; 41 | } 42 | a->arr[0] = x; 43 | a->size++; 44 | } 45 | 46 | 47 | void insertPos(struct node *a, int pos, int x){ 48 | int i; 49 | for(i=a->size; i>=pos-1; i--){ 50 | a->arr[i] = a->arr[i-1]; 51 | } 52 | a->arr[pos-1] = x; 53 | a->size++; 54 | } 55 | 56 | 57 | void insertLast(struct node *a, int x){ 58 | a->arr[a->size] = x; 59 | a->size++; 60 | } 61 | 62 | int length(struct node *a){ 63 | return a->size; 64 | } 65 | -------------------------------------------------------------------------------- /Assignment-8/adt.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct priorityQueue 6 | { 7 | int capacity; 8 | int size; 9 | int *elements; 10 | }; 11 | 12 | void init(struct priorityQueue *PQ, int max) 13 | { 14 | PQ->elements=(int *)malloc((max)*sizeof(int)); 15 | PQ->capacity=max; 16 | PQ->size=0; 17 | PQ->elements[0]= 999; 18 | } 19 | 20 | void insert(struct priorityQueue *PQ,int x) 21 | { 22 | int i; 23 | for(i=++PQ->size;PQ->elements[i/2]elements[i] = PQ->elements[i/2]; 25 | } 26 | PQ->elements[i]=x; 27 | } 28 | 29 | int delete(struct priorityQueue *PQ) 30 | { 31 | int i, child; 32 | int minelement, lastelement; 33 | minelement=PQ->elements[1]; 34 | lastelement=PQ->elements[PQ->size--]; 35 | for(i=1;(i *2)<= PQ->size;i=child) 36 | { 37 | child=i*2; 38 | if(PQ->elements[child+1] > PQ->elements[child]) 39 | child++; 40 | if(lastelement < PQ->elements[child]) 41 | PQ->elements[i]=PQ->elements[child]; 42 | else 43 | break; 44 | } 45 | PQ->elements[i]=lastelement; 46 | return minelement; 47 | } 48 | 49 | void displayb(struct priorityQueue *PQ){ 50 | int i,count=1; 51 | for(i=1;i<=PQ->size;i++){ 52 | printf("%d ",PQ->elements[i]); 53 | if(i==pow(2,count)-1){ 54 | printf("\n"); 55 | count++; 56 | } 57 | } 58 | printf("\n"); 59 | printf("\n"); 60 | } 61 | -------------------------------------------------------------------------------- /Assignment-6/Application/Application3ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct node { 6 | char data; 7 | struct node *lptr, *rptr; 8 | }; 9 | 10 | void insertFront(struct node *h, char c) { 11 | struct node *temp, *ptr; 12 | temp = (struct node *)malloc(sizeof(struct node)); 13 | temp->data = c; 14 | ptr = h->rptr; 15 | temp->rptr = ptr; 16 | h->rptr = temp; 17 | temp->lptr = h; 18 | if(ptr!=NULL) 19 | ptr->lptr = temp; 20 | } 21 | 22 | 23 | void display(struct node *h) { 24 | struct node *ptr, *prev; 25 | ptr = h->rptr; 26 | prev = h; 27 | printf("List In Forward: "); 28 | while(ptr!=NULL) { 29 | printf("%c ", ptr->data); 30 | prev = ptr; 31 | ptr = ptr->rptr; 32 | } 33 | // printf("\n\n"); 34 | // printf("list in Backward: "); 35 | // while(prev!=h) { 36 | // printf("%c ", prev->data); 37 | // prev = prev->lptr; 38 | // } 39 | printf("\n"); 40 | } 41 | 42 | void swap(struct node *h,int k) { 43 | struct node *end, *ptr; 44 | ptr = h->rptr; 45 | end = h; 46 | int temp; 47 | while(end->rptr!=NULL) 48 | end = end->rptr; 49 | for(int i=0;irptr; 51 | end=end->lptr; 52 | } 53 | temp=ptr->data; 54 | ptr->data=end->data; 55 | end->data=temp; 56 | 57 | 58 | 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /Assignment-3/PostfixApplication.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include"PostfixApplicationADT.h" 5 | 6 | int main() 7 | { 8 | int i; 9 | struct stack *s; 10 | s=(struct stack*)malloc(sizeof(struct stack)); 11 | 12 | createStack(s,7); 13 | 14 | char exp[20]; 15 | int n1,n2,n3,num; 16 | printf("Enter the expression :: "); 17 | scanf("%s",exp); 18 | 19 | while(exp[i] != '\0') 20 | { 21 | if(isdigit(exp[i])) 22 | { 23 | num = exp[i] - '0'; 24 | push(s,num); 25 | } 26 | else 27 | { 28 | n1 = pop(s); 29 | n2 = pop(s); 30 | switch(exp[i]) 31 | { 32 | case '+': 33 | { 34 | n3 = n1 + n2; 35 | break; 36 | } 37 | case '-': 38 | { 39 | n3 = n2 - n1; 40 | break; 41 | } 42 | case '*': 43 | { 44 | n3 = n1 * n2; 45 | break; 46 | } 47 | case '/': 48 | { 49 | n3 = n2 / n1; 50 | break; 51 | } 52 | } 53 | push(s,n3); 54 | } 55 | i++; 56 | } 57 | printf("\nThe result of expression: "); 58 | display(s); 59 | return 0; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /All Data Structure/Priarity_Queue/PriarityQueueADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct PriarityQueueADT 5 | { 6 | int size,capacity; 7 | int *array; 8 | }; 9 | 10 | struct PriarityQueueADT * init(struct PriarityQueueADT *pq,int max){ 11 | if(pq == NULL){ 12 | pq = (struct PriarityQueueADT *) malloc(sizeof(struct PriarityQueueADT)); 13 | pq->array = (int *) malloc(max * sizeof(int)); 14 | pq->capacity = max; 15 | pq->size = 0; 16 | pq->array[0] = -10; 17 | } 18 | return pq; 19 | } 20 | 21 | void Insert(struct PriarityQueueADT *pq,int x){ 22 | int i=0; 23 | 24 | for(i = ++pq->size; pq->array[i/2] > x; i/=2) 25 | pq->array[i] = pq->array[i/2]; 26 | pq->array[i] = x; 27 | } 28 | 29 | void Display(struct PriarityQueueADT *pq){ 30 | printf("\n"); 31 | for(int i=1; isize+1; i++) 32 | printf("%d ",pq->array[i]); 33 | } 34 | 35 | int Delete(struct PriarityQueueADT *pq){ 36 | if(pq->size == 0) return -999; 37 | int i, min, last, child; 38 | min = pq->array[1]; 39 | last = pq->array[pq->size--]; 40 | for(i = 1; (i*2) <= pq->size; i=child){ 41 | child = i*2; 42 | if(pq->array[child-1] < pq->array[child]) 43 | child++; 44 | if(pq->array[child] < last) 45 | pq->array[i] = pq->array[child]; 46 | else break; 47 | } 48 | pq->array[i] = last; 49 | return min; 50 | } -------------------------------------------------------------------------------- /Assignment-6/Application/Application2ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct node { 7 | char data; 8 | struct node *lptr, *rptr; 9 | }; 10 | 11 | void insertFront(struct node *h, char c) { 12 | struct node *temp, *ptr; 13 | temp = (struct node *)malloc(sizeof(struct node)); 14 | temp->data = c; 15 | ptr = h->rptr; 16 | temp->rptr = ptr; 17 | h->rptr = temp; 18 | temp->lptr = h; 19 | if(ptr!=NULL) ptr->lptr = temp; 20 | } 21 | 22 | void displayItems(struct node *h) { 23 | struct node *ptr, *prev; 24 | ptr = h->rptr; 25 | prev = h; 26 | 27 | printf("data : "); 28 | while(ptr!=NULL) { 29 | ptr->data=tolower(ptr->data); 30 | printf("%c,", ptr->data); 31 | prev = ptr; 32 | ptr = ptr->rptr; 33 | } 34 | printf("\n"); 35 | } 36 | 37 | 38 | void seperate(struct node *header,struct node *v,struct node *c){ 39 | struct node *ptr; 40 | ptr=header->rptr; 41 | while(ptr!=NULL){ 42 | ptr->data=toupper(ptr->data); 43 | if(ptr->data=='A'||ptr->data=='E'||ptr->data=='I'||ptr->data=='O'||ptr->data=='U') 44 | { 45 | insertFront(v,ptr->data); 46 | ptr=ptr->rptr; 47 | } 48 | else 49 | { 50 | insertFront(c,ptr->data); 51 | ptr=ptr->rptr; 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Assignment-6/Application/Application1ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct node { 6 | char data; 7 | struct node *lptr, *rptr; 8 | }; 9 | 10 | void insertFront(struct node *h, char c) { 11 | struct node *temp, *ptr; 12 | temp = (struct node *)malloc(sizeof(struct node)); 13 | temp->data = c; 14 | ptr = h->rptr; 15 | temp->rptr = ptr; 16 | h->rptr = temp; 17 | temp->lptr = h; 18 | if(ptr!=NULL) ptr->lptr = temp; 19 | } 20 | 21 | void displayItems(struct node *h) { 22 | struct node *ptr, *prev; 23 | ptr = h->rptr; 24 | prev = h; 25 | printf("Forward Display :\n"); 26 | while(ptr!=NULL) { 27 | printf("%c ", ptr->data); 28 | prev = ptr; 29 | ptr = ptr->rptr; 30 | } 31 | printf("\n"); 32 | printf("Reverse Display:\n"); 33 | while(prev!=h) { 34 | printf("%c ", prev->data); 35 | prev = prev->lptr; 36 | } 37 | printf("\n"); 38 | } 39 | 40 | int isPalindrome(struct node *h) { 41 | if(h->rptr==NULL) return 1; 42 | struct node *end, *ptr; 43 | ptr = h->rptr; 44 | end = h; 45 | while(end->rptr!=NULL) 46 | end = end->rptr; 47 | while(ptr->rptr!=NULL) { 48 | if(ptr->data!=end->data) 49 | return 0; 50 | else{ 51 | ptr = ptr->rptr; 52 | end = end->lptr; 53 | } 54 | } 55 | return 1; 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /Assignment-3/ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct stack { 5 | int arr[100]; 6 | int size,top; 7 | }; 8 | int checkemp(struct stack *S){ 9 | if(S->top == -1) return 1; 10 | else return 0; 11 | } 12 | 13 | 14 | int checkfil(struct stack *S){ 15 | if(S->top == S->size-1) 16 | return 1; 17 | return 0; 18 | } 19 | 20 | int gettop(struct stack *S){ 21 | if(checkemp(S)) 22 | return -1; 23 | else return S->arr[S->top]; 24 | } 25 | 26 | 27 | void createStack(struct stack *S, int lim) 28 | { 29 | S->size = lim; 30 | S->top = -1; 31 | } 32 | 33 | void push(struct stack *S, int x) 34 | { 35 | if(checkfil(S)){ 36 | printf("FULL"); 37 | } 38 | else { 39 | S->top++; 40 | S->arr[S->top] = x; 41 | } 42 | 43 | } 44 | 45 | 46 | void display(struct stack *S) 47 | { 48 | struct stack *ptr=S; 49 | for(int i=0; itop+1; i++){ 50 | printf("%d ",ptr->arr[i]); 51 | } 52 | 53 | } 54 | 55 | 56 | void pop (struct stack *S) 57 | { 58 | if(S->top)S->top--; 59 | } 60 | 61 | 62 | 63 | int big(struct stack *S){ 64 | int i=0, max = S->arr[i]; 65 | for(i=1; itop+1; i++){ 66 | if(max < S->arr[i]) 67 | max = S->arr[i]; 68 | } 69 | return max; 70 | } 71 | 72 | void Binary(struct stack *S, int data){ 73 | int n = data; 74 | 75 | for(int i=0;n>0;i++) 76 | { 77 | push(S,n%2); 78 | n=n/2; 79 | } 80 | n=data; 81 | printf("%d : ",data); 82 | for(int i=0;n>0;i++) 83 | { 84 | printf("%d",gettop(S)); 85 | pop(S); 86 | n=n/2; 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /Assignment-8/adt1.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct priorityQueue 6 | { 7 | int capacity; 8 | int size; 9 | char *empid; 10 | long int *salary; 11 | }; 12 | 13 | void init(struct priorityQueue *PQ, int max) 14 | { 15 | PQ->salary=(long int *)malloc((max)*sizeof(long int)); 16 | PQ->empid=(char *)malloc((max)*sizeof(char)); 17 | PQ->capacity=max; 18 | PQ->size=0; 19 | PQ->salary[0]= 100000; 20 | PQ->empid[0]='Z'; 21 | } 22 | 23 | void insert(struct priorityQueue *PQ,char id,long int x) 24 | { 25 | int i; 26 | for(i=++PQ->size;PQ->salary[i/2]salary[i] = PQ->salary[i/2]; 28 | PQ->empid[i] = PQ->empid[i/2]; 29 | } 30 | PQ->salary[i]=x; 31 | PQ->empid[i]=id; 32 | } 33 | 34 | int delete(struct priorityQueue *PQ) 35 | { 36 | int i, child; 37 | int minelement, lastelement; 38 | char last; 39 | minelement=PQ->salary[1]; 40 | lastelement=PQ->salary[PQ->size]; 41 | last=PQ->empid[PQ->size--]; 42 | for(i=1;(i *2)<= PQ->size;i=child) 43 | { 44 | child=i*2; 45 | if(PQ->salary[child+1] > PQ->salary[child]) 46 | child++; 47 | if(lastelement < PQ->salary[child]){ 48 | PQ->salary[i]=PQ->salary[child]; 49 | PQ->empid[i]=PQ->empid[child]; 50 | } 51 | else 52 | break; 53 | } 54 | PQ->salary[i]=lastelement; 55 | PQ->empid[i]=last; 56 | return minelement; 57 | } 58 | 59 | void display(struct priorityQueue *PQ){ 60 | int i,count=1; 61 | for(i=1;i<=PQ->size;i++){ 62 | printf("%ld %c ",PQ->salary[i],PQ->empid[i]); 63 | if(i==pow(2,count)-1){ 64 | printf("\n"); 65 | count++; 66 | } 67 | } 68 | printf("\n"); 69 | printf("\n"); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Assignment-4/QueueADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | char *job; 6 | int time; 7 | struct node *next; 8 | }; 9 | 10 | void createQueue(struct node *ptr[],char *size){ 11 | ptr[0]->next = NULL; 12 | ptr[1]->next = NULL; 13 | ptr[0]->job = size; 14 | ptr[0]->time = 0; 15 | } 16 | 17 | 18 | void enqueue(struct node *ptr[],char *j,int t){ 19 | struct node *temp; 20 | temp = (struct node*)malloc(sizeof(struct node)); 21 | temp->job = j; 22 | temp->time = t; 23 | int size = atoi(ptr[0]->job); 24 | if(ptr[0]->time == size){ 25 | printf("queue is full\n"); 26 | } 27 | else{ 28 | if(ptr[0]->next==NULL && ptr[1]->next==NULL){ 29 | ptr[0]->next = temp; 30 | ptr[1] = temp; 31 | ptr[1]->next = ptr[0]; 32 | } 33 | else{ 34 | temp->next = ptr[1]->next; 35 | ptr[1]->next = temp; 36 | ptr[1] = temp; 37 | } 38 | ptr[0]->time++; 39 | } 40 | printf("enqueued Element : (%s,%d)\n",j,t); 41 | } 42 | 43 | void display(struct node *ptr[]){ 44 | struct node *temp; 45 | 46 | printf("Queue data : "); 47 | temp = (struct node*)malloc(sizeof(struct node)); 48 | temp = ptr[0]->next; 49 | while(temp != ptr[0]){ 50 | printf("(%s,%d) ",temp->job,temp->time); 51 | temp = temp->next; 52 | } 53 | printf("\n"); 54 | } 55 | 56 | void dequeue(struct node *ptr[]){ 57 | struct node *temp; 58 | temp = (struct node*)malloc(sizeof(struct node)); 59 | ptr[1]->next = ptr[0]->next; 60 | temp = ptr[0]; 61 | ptr[0] = ptr[0]->next; 62 | printf("Element dequeued \n"); 63 | free(temp); 64 | } 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Assignment-12/hashTADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // code by jaanu sri... 6 | struct node 7 | { 8 | int data; 9 | struct node *next; 10 | }; 11 | 12 | struct hashTable 13 | { 14 | struct node *list[10]; 15 | int size; 16 | }; 17 | 18 | void init(struct hashTable *H, int limit) 19 | { 20 | //H = (struct hashTable *)malloc(sizeof(struct hashTable)); 21 | H->size = limit; 22 | for (int i = 0 ; i < limit ; i++) 23 | { 24 | H->list[i] = (struct node*)malloc(sizeof(struct node)); 25 | H->list[i]->next = NULL; 26 | } 27 | } 28 | 29 | void insertnode(struct node *p, struct node *t) 30 | { 31 | if (p->next == NULL) p->next = t; 32 | else insertnode(p->next, t); 33 | } 34 | 35 | void insert(struct hashTable *H, int x) 36 | { 37 | int pos; 38 | pos = x % H->size; 39 | struct node *temp, *ptr; 40 | temp = (struct node*)malloc(sizeof(struct node)); 41 | temp->data = x; 42 | temp->next = NULL; 43 | ptr = H->list[pos]; 44 | insertnode(ptr, temp); 45 | 46 | return; 47 | } 48 | 49 | void display(struct hashTable *H) 50 | { 51 | struct node *ptr; 52 | for (int i = 0 ; i < H->size ; i++) 53 | { 54 | printf("%d : ", i); 55 | ptr = H->list[i]->next; 56 | while (ptr!=NULL) 57 | { 58 | printf("%d ",ptr->data); 59 | ptr = ptr->next; 60 | } 61 | printf("\n"); 62 | } 63 | } 64 | 65 | int search (struct hashTable *H, int key) 66 | { 67 | struct node *ptr; 68 | int pos = key % H->size; 69 | ptr = H->list[pos]->next; 70 | while (ptr != NULL) 71 | { 72 | if (ptr->data == key) return pos; 73 | ptr = ptr->next; 74 | } 75 | return -1; 76 | } 77 | -------------------------------------------------------------------------------- /Assignment-12/Application/applic.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // code by jaanu sri... 6 | struct QhashTable 7 | { 8 | int *list; 9 | int size; 10 | }; 11 | 12 | struct DhashTable 13 | { 14 | int *list; 15 | int size; 16 | }; 17 | 18 | void init(struct QhashTable *QH, struct DhashTable *DH, int limit) 19 | { 20 | QH->size = limit; 21 | QH->list = (int *)malloc(limit*sizeof(int)); 22 | DH->size = limit; 23 | DH->list = (int *)malloc(limit*sizeof(int)); 24 | } 25 | 26 | int QgetPosition(struct QhashTable *H, int x, int i) 27 | { 28 | //printf("\n%d ",i); 29 | return ((x%H->size)+((i+1)*(i+1)))%H->size; 30 | } 31 | 32 | int DgetPosition(struct DhashTable *H, int x, int pos) 33 | { 34 | //printf("\n%d ",i); 35 | return (pos+(7-(x%7)))%H->size; 36 | } 37 | 38 | void insertQuad(struct QhashTable *H, int x, int pos, int i) 39 | { 40 | if (H->list[pos]==0) 41 | { 42 | H->list[pos] = x; 43 | } 44 | else 45 | { 46 | //printf("%d ", i); 47 | pos = QgetPosition(H, x, i); 48 | insertQuad(H, x, pos, i+1); 49 | } 50 | return; 51 | } 52 | 53 | void insertDoub(struct DhashTable *H, int x, int pos) 54 | { 55 | if (H->list[pos]==0) 56 | { 57 | H->list[pos] = x; 58 | } 59 | else 60 | { 61 | pos = DgetPosition(H, x, pos); 62 | insertDoub(H, x, pos); 63 | } 64 | return; 65 | } 66 | 67 | void display_Quadprob(struct QhashTable *QH) 68 | { 69 | for (int i = 0 ; i < QH->size ; i++) 70 | { 71 | printf("%d -> %d\n", i, QH->list[i]); 72 | } 73 | } 74 | 75 | void display_DoubleHash(struct DhashTable *DH) 76 | { 77 | for (int i = 0 ; i < DH->size ; i++) 78 | { 79 | printf("%d -> %d\n", i, DH->list[i]); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Assignment-4/Application/jobADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct node { 6 | char jobid[5]; 7 | int burst; 8 | struct node *next; 9 | }; 10 | struct header{ 11 | int size; 12 | int counter; 13 | }; 14 | 15 | 16 | void create(struct header *head,int size) { 17 | head->size=size; 18 | head->counter=0; 19 | 20 | 21 | } 22 | 23 | void enqueue(struct header *head,struct node *ptr[],char job[],int time) { 24 | struct node *temp; 25 | temp=(struct node*)malloc(sizeof(struct node)); 26 | temp->burst=time; 27 | strcpy(temp->jobid,job); 28 | temp->next=NULL; 29 | 30 | if(head->countersize) { 31 | if(ptr[1]==NULL) { 32 | ptr[0]=ptr[1]=temp; 33 | ptr[1]->next=ptr[0]; 34 | head->counter++; 35 | 36 | } 37 | else { 38 | ptr[1]->next=temp; 39 | ptr[1]=temp; 40 | ptr[1]->next=ptr[0]; 41 | head->counter++; 42 | 43 | 44 | } 45 | } 46 | else { 47 | printf("The Queue is full\n"); 48 | } 49 | 50 | 51 | printf("enqueue\n"); 52 | 53 | 54 | } 55 | 56 | void dequeue(struct header *head,struct node *ptr[]) { 57 | 58 | if(ptr[0]==NULL && ptr[1]==NULL) { 59 | printf("The Queue is Empty"); 60 | } 61 | else if (ptr[0]==ptr[1]) { 62 | ptr[0]=ptr[1]=0; 63 | head->counter--; 64 | 65 | } 66 | else { 67 | ptr[0]=ptr[0]->next; 68 | ptr[1]->next=ptr[0]; 69 | head->counter--; 70 | } 71 | printf("dequeue\n"); 72 | } 73 | 74 | void display(struct header *head,struct node *ptr[]) { 75 | struct node *temp; 76 | temp=ptr[0]; 77 | printf("The Queue element : "); 78 | if(ptr[0]==0 && ptr[1]==0) { 79 | printf("The Queue is Empty\n"); 80 | } 81 | else { 82 | while(temp->next!=ptr[0]) { 83 | printf("(%s,%d) ",temp->jobid,temp->burst); 84 | temp=temp->next; 85 | } 86 | printf("(%s,%d) \n",temp->jobid,temp->burst); 87 | } 88 | 89 | } 90 | 91 | -------------------------------------------------------------------------------- /Assignment-4/Application/Job scheduling.c: -------------------------------------------------------------------------------- 1 | #include "jobADT.h" 2 | int avgtime(struct node *ptr[]){ 3 | struct node *temp; 4 | temp=(struct node*)malloc(sizeof(struct node)); 5 | int sum=ptr[0]->burst,count=1; 6 | temp=ptr[0]->next; 7 | while(temp!=ptr[0]){ 8 | sum+=temp->burst; 9 | count++; 10 | temp=temp->next; 11 | } 12 | return sum/count; 13 | } 14 | 15 | void insert(struct node *ptr[],struct node *ptr1[],struct header *Head1,struct header *Head2,char *job,int time){ 16 | if(ptr[0]==NULL){ 17 | enqueue(Head1,ptr,job,time); 18 | } 19 | else if(ptr1[0]==NULL){ 20 | enqueue(Head2,ptr1,job,time); 21 | } 22 | else if(avgtime(ptr) 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node *lptr,*rptr; 7 | }; 8 | struct node* createNode(int x) 9 | { 10 | struct node *temp; 11 | temp=(struct node*)malloc(sizeof(struct node)); 12 | temp->data=x; 13 | return temp; 14 | } 15 | void insert(struct node *header, int x) 16 | { 17 | struct node *temp,*p; 18 | temp=createNode(x); 19 | p=header->rptr; 20 | temp->rptr=header->rptr; 21 | header->rptr=temp; 22 | temp->lptr=header; 23 | if(p!=NULL) 24 | p->lptr=temp; 25 | } 26 | void display(struct node *header) 27 | { 28 | struct node *ptr,*end; 29 | ptr=header->rptr; 30 | while(ptr!=NULL) 31 | { 32 | printf("%d ",ptr->data); 33 | end=ptr; 34 | ptr=ptr->rptr; 35 | } 36 | printf("\n"); 37 | } 38 | 39 | int search(struct node *header,int key) 40 | { 41 | struct node *ptr; 42 | ptr=header->rptr; 43 | while(ptr!=NULL) 44 | { 45 | if(ptr->data==key) 46 | return ptr->data; 47 | else 48 | ptr=ptr->rptr; 49 | } 50 | return -1; 51 | } 52 | 53 | void delete(struct node *header, int num) 54 | { 55 | struct node *ptr,*l,*r; 56 | ptr=header->rptr; 57 | while(ptr!=NULL) 58 | { 59 | if(ptr->data==num) 60 | { 61 | l=ptr->lptr; 62 | r=ptr->rptr; 63 | l->rptr=r; 64 | r->lptr=l; 65 | free(ptr); 66 | } 67 | else 68 | { 69 | ptr=ptr->rptr; 70 | } 71 | } 72 | } 73 | 74 | void reverse(struct node *head) 75 | { 76 | struct node *temp = NULL, *current = head->lptr; 77 | while (current != NULL) { 78 | temp = current->lptr; 79 | current->lptr = current->rptr; 80 | current->rptr = temp; 81 | current = current->lptr; 82 | } 83 | if (temp != NULL) 84 | head = temp->lptr; 85 | } 86 | -------------------------------------------------------------------------------- /Assignment-12/Application/main.c: -------------------------------------------------------------------------------- 1 | #include "applic.h" 2 | 3 | // code by jaanu sri... 4 | int main() 5 | { 6 | int size, op, elmt, s, pos1, pos2; 7 | struct QhashTable *QH; 8 | struct DhashTable *DH; 9 | //printf("Hi"); 10 | QH = (struct QhashTable *)malloc(sizeof(struct QhashTable)); 11 | DH = (struct DhashTable *)malloc(sizeof(struct DhashTable)); 12 | printf("\nEnter the size of the Hash Table : "); 13 | scanf("%d", &size); 14 | init(QH, DH, size); 15 | 16 | elmt = 23; 17 | pos1 = elmt % QH->size; 18 | pos2 = elmt % DH->size; 19 | insertQuad(QH, elmt, pos1, 0); 20 | insertDoub(DH, elmt, pos2); 21 | elmt = 45; 22 | pos1 = elmt % QH->size; 23 | pos2 = elmt % DH->size; 24 | insertQuad(QH, elmt, pos1, 0); 25 | insertDoub(DH, elmt, pos2); 26 | elmt = 69; 27 | pos1 = elmt % QH->size; 28 | pos2 = elmt % DH->size; 29 | insertQuad(QH, elmt, pos1, 0); 30 | insertDoub(DH, elmt, pos2); 31 | elmt = 87; 32 | pos1 = elmt % QH->size; 33 | pos2 = elmt % DH->size; 34 | insertQuad(QH, elmt, pos1, 0); 35 | insertDoub(DH, elmt, pos2); 36 | elmt = 45; 37 | pos1 = elmt % QH->size; 38 | pos2 = elmt % DH->size; 39 | insertQuad(QH, elmt, pos1, 0); 40 | insertDoub(DH, elmt, pos2); 41 | elmt = 67; 42 | pos1 = elmt % QH->size; 43 | pos2 = elmt % DH->size; 44 | insertQuad(QH, elmt, pos1, 0); 45 | insertDoub(DH, elmt, pos2); 46 | elmt = 54; 47 | pos1 = elmt % QH->size; 48 | pos2 = elmt % DH->size; 49 | insertQuad(QH, elmt, pos1, 0); 50 | insertDoub(DH, elmt, pos2); 51 | elmt = 66; 52 | pos1 = elmt % QH->size; 53 | pos2 = elmt % DH->size; 54 | insertQuad(QH, elmt, pos1, 0); 55 | insertDoub(DH, elmt, pos2); 56 | 57 | printf("display_Quadprob:\n"); 58 | display_Quadprob(QH); 59 | printf("display_DoubleHash:\n"); 60 | display_DoubleHash(DH); 61 | 62 | return 0; 63 | } 64 | 65 | // thank you jaanu sri... 66 | -------------------------------------------------------------------------------- /Assignment 2/polyABT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | struct Node { 6 | int coeff; 7 | int pow; 8 | struct Node* next; 9 | }; 10 | 11 | void create_node(int x, int y, struct Node** temp) 12 | { 13 | struct Node *r, *z; 14 | z = *temp; 15 | if (z == NULL) { 16 | r = (struct Node*)malloc(sizeof(struct Node)); 17 | r->coeff = x; 18 | r->pow = y; 19 | *temp = r; 20 | r->next = (struct Node*)malloc(sizeof(struct Node)); 21 | r = r->next; 22 | r->next = NULL; 23 | } 24 | else { 25 | r->coeff = x; 26 | r->pow = y; 27 | r->next = (struct Node*)malloc(sizeof(struct Node)); 28 | r = r->next; 29 | r->next = NULL; 30 | } 31 | } 32 | 33 | void polyadd(struct Node* poly1, struct Node* poly2, 34 | struct Node* poly) 35 | { 36 | while (poly1->next && poly2->next) { 37 | if (poly1->pow > poly2->pow) { 38 | poly->pow = poly1->pow; 39 | poly->coeff = poly1->coeff; 40 | poly1 = poly1->next; 41 | } 42 | 43 | else if (poly1->pow < poly2->pow) { 44 | poly->pow = poly2->pow; 45 | poly->coeff = poly2->coeff; 46 | poly2 = poly2->next; 47 | } 48 | 49 | else { 50 | poly->pow = poly1->pow; 51 | poly->coeff = poly1->coeff + poly2->coeff; 52 | poly1 = poly1->next; 53 | poly2 = poly2->next; 54 | } 55 | 56 | poly->next 57 | = (struct Node*)malloc(sizeof(struct Node)); 58 | poly = poly->next; 59 | poly->next = NULL; 60 | } 61 | while (poly1->next || poly2->next) { 62 | if (poly1->next) { 63 | poly->pow = poly1->pow; 64 | poly->coeff = poly1->coeff; 65 | poly1 = poly1->next; 66 | } 67 | if (poly2->next) { 68 | poly->pow = poly2->pow; 69 | poly->coeff = poly2->coeff; 70 | poly2 = poly2->next; 71 | } 72 | poly->next 73 | = (struct Node*)malloc(sizeof(struct Node)); 74 | poly = poly->next; 75 | poly->next = NULL; 76 | } 77 | } 78 | 79 | void display(struct Node* node) 80 | { 81 | while (node->next != NULL) { 82 | printf("%dx^%d", node->coeff, node->pow); 83 | node = node->next; 84 | if (node->coeff >= 0) { 85 | if (node->next != NULL) 86 | printf("+"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /All Data Structure/BST/BinarySearchTreeADT.h: -------------------------------------------------------------------------------- 1 | #include "queue.h" 2 | 3 | 4 | struct tree* insertBST(struct tree *t, int x){ 5 | if(t == NULL){ 6 | t = (struct tree *) malloc(sizeof(struct tree)); 7 | t->data = x; 8 | t->right = NULL; 9 | t->left = NULL; 10 | } 11 | else if(x > t->data) 12 | t->right = insertBST(t->right,x); 13 | else if(x < t->data) 14 | t->left = insertBST(t->left,x); 15 | return t; 16 | } 17 | 18 | void inorderBST(struct tree *t){ 19 | if(t==NULL) return ; 20 | if(t->left != NULL) 21 | inorderBST(t->left); 22 | printf("%d ",t->data); 23 | if(t->right != NULL) 24 | inorderBST(t->right); 25 | } 26 | struct tree * findmax(struct tree *t){ 27 | if(t->right != NULL) t->right = findmax(t->right); 28 | return t; 29 | } 30 | struct tree * findmin(struct tree *t){ 31 | if(t->left != NULL) t->left = findmin(t->left); 32 | return t; 33 | } 34 | struct tree * deleteBST(struct tree *t, int x){ 35 | struct tree *temp; 36 | if(t==NULL)return t; 37 | else if(x> t->data) t->right = deleteBST(t->right,x); 38 | else if(x < t->data) t->left = deleteBST(t->left,x); 39 | else if(t->left != NULL && t->right != NULL) { 40 | temp = findmin(t->right); 41 | t->data = temp->data; 42 | t->right = deleteBST(temp->right,temp->data); 43 | } 44 | else{ 45 | temp = t; 46 | if(t->right == NULL) t = t->left; 47 | else if(t->left == NULL) t = t->right; 48 | } 49 | return t; 50 | } 51 | // void levelorderBST(struct tree *t){ 52 | // if(t == NULL) return ; 53 | // struct queue *q = createQueue(20); 54 | // enqueue(q,t); 55 | // int i=0; 56 | // // printf("%d first queue \n",peek(q)->data); 57 | // struct tree *temp = t; 58 | // while(!isEmpty(q)){ 59 | // temp = peek(q); 60 | // printf("%d ",temp->data); 61 | // // printf("\nQueue Print %d: ",i++);display(q); 62 | // if(temp->left != NULL ) enqueue(q,temp->left); 63 | // if(temp->right != NULL ) enqueue(q,temp->right); 64 | // dequeue(q); 65 | // } 66 | // } -------------------------------------------------------------------------------- /Assignment-9/Application/Application2.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Queue.h" 4 | #include "Stack.h" 5 | 6 | struct graph{ 7 | int vertex; 8 | int edges; 9 | int **adj; 10 | char data[100][20]; 11 | }; 12 | 13 | struct graph* create_graph(){ 14 | int i,j,k,data; 15 | struct graph *g; 16 | g = (struct graph *) malloc(sizeof(struct graph)); 17 | printf("Enter the number of Nodes and Edges (N,E) : "); 18 | scanf("%d %d",&g->vertex,&g->edges); 19 | g->adj = (int **) malloc(g->vertex * sizeof(int)); 20 | g->adj[0] = (int *) malloc(g->vertex * sizeof(int)); 21 | 22 | for(i=0; ivertex; i++){ 23 | g->adj[i] = (int *) malloc(g->vertex * sizeof(int)); 24 | for(j=0; jvertex; j++) 25 | g->adj[i][j] = 0; 26 | } 27 | printf("Enter the nodes in pair (a -> b) \n"); 28 | for(i=0; iedges; i++){ 29 | scanf("%d",&j); 30 | scanf("%d",&k); 31 | g->adj[j-1][k-1] = 1; 32 | } 33 | printf("Enter the all data : \n"); 34 | for(int i=0; ivertex; i++) 35 | scanf("%s",g->data[i]); 36 | return g; 37 | } 38 | 39 | void displayadj(struct graph *g){ 40 | int u,v; 41 | printf("Adj : matrix \n"); 42 | for(u=0; uvertex; u++){ 43 | for(v=0; vvertex; v++) 44 | printf("%d ",g->adj[u][v]); 45 | printf("\n"); 46 | } 47 | } 48 | 49 | void BFS(struct graph *g, int start,int *visit){ 50 | 51 | int i; 52 | struct queue *q = createQueue(20); 53 | printf("\n\n"); 54 | printf("BFS : "); 55 | start--; 56 | printf("%s --> ",g->data[start]); 57 | visit[start] = 1; 58 | enqueue(q,start); 59 | while (!isEmpty(q)) 60 | { 61 | int deq = dequeue(q); 62 | for(i=0; ivertex; i++){ 63 | if(g->adj[deq][i] == 1 && visit[i]==0){ 64 | printf("%s --> ",g->data[i]); 65 | visit[i] = 1; 66 | enqueue(q,i); 67 | } 68 | } 69 | } 70 | printf("*\n\n"); 71 | } 72 | /* 73 | Test case 1 74 | 5 3 75 | 1 2 76 | 1 3 77 | 4 5 78 | 1 79 | 0 80 | 2 81 | 4 82 | 5 83 | 84 | */ 85 | -------------------------------------------------------------------------------- /Assignment 2/ABT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | void reverseList(struct node *h) { 9 | struct node *ptr, *after, *prev, *last; 10 | prev=h->next; 11 | last=prev; 12 | ptr=prev->next; 13 | while(ptr->next!=NULL) 14 | { 15 | after=ptr->next; 16 | ptr->next=prev; 17 | prev=ptr; 18 | ptr=after; 19 | } 20 | ptr->next=prev; 21 | h->next=ptr; 22 | last->next=NULL; 23 | } 24 | 25 | 26 | void insert(struct node *header,int data) 27 | { 28 | struct node *temp,*ptr; 29 | temp = (struct node*) malloc(sizeof(struct node)); 30 | 31 | temp->next = header->next; 32 | header->next = temp; 33 | temp->data = data; 34 | } 35 | 36 | void display(struct node *header) 37 | { 38 | struct node *ptr = header->next; 39 | while(ptr!=NULL){ 40 | printf("%d ",ptr->data); 41 | ptr = ptr->next; 42 | } 43 | } 44 | 45 | int length(struct node *header) 46 | { 47 | struct node *ptr = header->next; 48 | int count=0; 49 | while(ptr!=NULL){ 50 | count++; 51 | ptr = ptr->next; 52 | } 53 | return count; 54 | } 55 | 56 | int search(struct node *header, int key) 57 | { 58 | struct node *ptr = header->next; 59 | while(ptr!=NULL){ 60 | if(ptr->data == key){ 61 | return ptr->data; 62 | } 63 | ptr = ptr->next; 64 | } 65 | return -1; 66 | } 67 | 68 | void delet(struct node *header, int key) 69 | { 70 | 71 | struct node *ptr = header->next,*temp; 72 | temp = header->next; 73 | while(ptr!=NULL){ 74 | if(ptr->data == key){ 75 | temp->next=ptr->next; 76 | free(ptr); 77 | } 78 | else{ 79 | temp = ptr; 80 | ptr = ptr->next; 81 | 82 | } 83 | 84 | } 85 | } 86 | 87 | 88 | 89 | int middle(struct node *header) 90 | { 91 | struct node *ptr = header->next; 92 | int len = length(header); 93 | int middle, count =1; 94 | if(len%2==1){ 95 | middle = (len/2)+1; 96 | } 97 | else{ 98 | middle = len/2; 99 | } 100 | 101 | while(ptr!=NULL){ 102 | if(count==middle){ 103 | return(ptr->data); 104 | } 105 | ptr=ptr->next; 106 | count++; 107 | } 108 | } 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /Assignment-9/Application/Application1.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Queue.h" 4 | #include "Stack.h" 5 | 6 | struct graph{ 7 | int vertex; 8 | int edges; 9 | int **adj; 10 | char data[100][20]; 11 | }; 12 | 13 | struct graph* create_graph(){ 14 | int i,j,k,data; 15 | struct graph *g; 16 | g = (struct graph *) malloc(sizeof(struct graph)); 17 | printf("Enter the number of Nodes and Edges (N,E) : "); 18 | scanf("%d %d",&g->vertex,&g->edges); 19 | g->adj = (int **) malloc(g->vertex * sizeof(int)); 20 | g->adj[0] = (int *) malloc(g->vertex * sizeof(int)); 21 | 22 | for(i=0; ivertex; i++){ 23 | g->adj[i] = (int *) malloc(g->vertex * sizeof(int)); 24 | for(j=0; jvertex; j++) 25 | g->adj[i][j] = 0; 26 | } 27 | printf("Enter the nodes in pair (a -> b) \n"); 28 | for(i=0; iedges; i++){ 29 | scanf("%d",&j); 30 | scanf("%d",&k); 31 | g->adj[j-1][k-1] = 1; 32 | } 33 | printf("Enter the all data : \n"); 34 | for(int i=0; ivertex; i++) 35 | scanf("%s",g->data[i]); 36 | return g; 37 | } 38 | 39 | void displayadj(struct graph *g){ 40 | int u,v; 41 | printf("Adj : matrix \n"); 42 | for(u=0; uvertex; u++){ 43 | for(v=0; vvertex; v++) 44 | printf("%d ",g->adj[u][v]); 45 | printf("\n"); 46 | } 47 | } 48 | 49 | void BFS(struct graph *g, int start, int dis){ 50 | 51 | int i=0,visit[g->vertex],flag =0; 52 | dis--; 53 | for(i=0; ivertex; i++) visit[i]=0; 54 | struct queue *q = createQueue(20); 55 | printf("\n\n"); 56 | printf("BFS : "); 57 | start--; 58 | visit[start] = 1; 59 | enqueue(q,start); 60 | while (!isEmpty(q)) 61 | { 62 | int deq = dequeue(q); 63 | for(i=0; ivertex; i++){ 64 | if(g->adj[deq][i] == 1 && visit[i]==0 ){ 65 | visit[i] = 1; 66 | enqueue(q,i); 67 | if(g->adj[deq][i] == g->adj[deq][dis]){ 68 | flag =1; 69 | break; 70 | } 71 | } 72 | if(flag) break; 73 | } 74 | } 75 | if(flag == 0) printf("NO Path\n"); 76 | else printf("Ther is a Path \n"); 77 | printf("*\n\n"); 78 | } 79 | /* 80 | Test case 1 81 | 5 3 82 | 1 2 83 | 1 3 84 | 4 5 85 | 1 86 | 0 87 | 2 88 | 4 89 | 5 90 | 91 | */ 92 | -------------------------------------------------------------------------------- /All Data Structure/Simple Linked List/LinkedListADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | void display(struct node *h){ 9 | struct node *ptr; 10 | ptr = h->next; 11 | while(ptr != NULL){ 12 | printf("%d ",ptr->data); 13 | ptr = ptr->next; 14 | } 15 | } 16 | 17 | struct node * create(struct node *h){ 18 | struct node *temp = (struct node *) malloc(sizeof(struct node)); 19 | if(h == NULL){ 20 | temp->next = NULL; 21 | return temp; 22 | } 23 | } 24 | 25 | void insertFrent(struct node *h, int x){ 26 | 27 | struct node *temp = (struct node *) malloc(sizeof(struct node)); 28 | temp->next = h->next; 29 | temp->data = x; 30 | h->next = temp; 31 | } 32 | 33 | void insertPos(struct node *h, int pos, int x){ 34 | 35 | struct node *temp = (struct node *) malloc(sizeof(struct node)); 36 | 37 | struct node *ptr = h; 38 | for(int i=0; inext; 40 | temp->next = ptr->next; 41 | temp->data = x; 42 | ptr->next = temp; 43 | } 44 | 45 | void insertEnd(struct node *h, int x){ 46 | 47 | struct node *temp = (struct node *) malloc(sizeof(struct node)); 48 | 49 | struct node *ptr = h; 50 | while(ptr->next != NULL) 51 | ptr = ptr->next; 52 | temp->next = ptr->next; 53 | temp->data = x; 54 | ptr->next = temp; 55 | } 56 | 57 | void insertByKey(struct node *h, int key, int x){ 58 | 59 | struct node *temp = (struct node *) malloc(sizeof(struct node)); 60 | 61 | struct node *ptr, *prev; 62 | ptr = h->next; 63 | prev = h; 64 | while(ptr->next != NULL){ 65 | if(ptr->data == key) 66 | break; 67 | ptr = ptr->next; 68 | prev = prev->next; 69 | } 70 | prev->next = temp; 71 | temp->next = ptr; 72 | temp->data = x; 73 | } 74 | 75 | void deleteFrent(struct node *h){ 76 | h->next = h->next->next; 77 | } 78 | 79 | void deleteEnd(struct node *h){ 80 | struct node *ptr, *prev; 81 | ptr = h->next; 82 | prev = h; 83 | while(ptr->next != NULL){ 84 | ptr = ptr->next; 85 | prev = prev->next; 86 | } 87 | prev->next = ptr->next; 88 | } 89 | 90 | void deleteKey(struct node *h, int key){ 91 | struct node *ptr, *prev; 92 | ptr = h->next; 93 | prev = h; 94 | while(ptr->next != NULL){ 95 | if(ptr->data == key) 96 | break; 97 | ptr = ptr->next; 98 | prev = prev->next; 99 | } 100 | prev->next = ptr->next; 101 | } 102 | 103 | -------------------------------------------------------------------------------- /Assignment-11/Application/SellsortADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node1 { 5 | int *arr; 6 | int size; 7 | }; 8 | 9 | void init(struct node1 *a, int siz) 10 | { 11 | a->size = siz; 12 | a->arr = (int*) malloc(siz*(2+1) *sizeof(int)); 13 | } 14 | 15 | void InsertElement(struct node1 *a, int *array){ 16 | int i; 17 | //a->arr[0] = -99; 18 | for(i=0; isize; i++){ 19 | a->arr[i] = array[i]; 20 | } 21 | } 22 | 23 | void Display(struct node1 *a){ 24 | printf("Array Element : "); 25 | for(int i=0; isize; i++){ 26 | printf("%d ",a->arr[i]); 27 | } 28 | printf("\n\n"); 29 | } 30 | 31 | void sellSort(struct node1 *a) 32 | 33 | { 34 | for (int i = a->size / 2; i > 0; i = i / 2){ 35 | for (int j = i; j < a->size; j++){ 36 | for(int k = j - i; k >= 0; k = k - i){ 37 | if (a->arr[k+i] >= a->arr[k]){ 38 | break; 39 | } 40 | else 41 | { 42 | int temp = a->arr[k]; 43 | a->arr[k] = a->arr[k+i]; 44 | a->arr[k+i] = temp; 45 | 46 | } 47 | } 48 | } 49 | } 50 | return ; 51 | } 52 | 53 | void appearsonce(struct node1 *a, int key) { 54 | int high = a->size -1,low =0,mid=0; 55 | while (low <= high) { 56 | mid = low + (high - low) / 2; 57 | if (a->arr[mid] == key){ 58 | break; 59 | } 60 | 61 | if (a->arr[mid] < key) 62 | low = mid + 1; 63 | 64 | else 65 | high = mid - 1; 66 | } 67 | 68 | if(a->arr[mid+1] == a->arr[mid] || a->arr[mid-1] == a->arr[mid]) 69 | printf("%d is repeted\n",a->arr[mid]); 70 | else 71 | printf("%d is Not repeted\n",a->arr[mid]); 72 | } 73 | 74 | 75 | void appearscount(struct node1 *a, int key) { 76 | int high = a->size -1,low =0,mid=0; 77 | while (low <= high) { 78 | mid = low + (high - low) / 2; 79 | if (a->arr[mid] == key){ 80 | break; 81 | } 82 | 83 | if (a->arr[mid] < key) 84 | low = mid + 1; 85 | 86 | else 87 | high = mid - 1; 88 | } 89 | 90 | 91 | low = 1; 92 | if(a->arr[mid+1] == a->arr[mid] || a->arr[mid-1] == a->arr[mid]) 93 | low =0; 94 | else 95 | low =1; 96 | 97 | printf("%d this is value %d index\n",a->arr[mid],mid); 98 | 99 | int count =0,i=1; 100 | if(low == 0){ 101 | 102 | do{ 103 | if(a->arr[mid+i] == a->arr[mid] || a->size-1 < mid+i){ 104 | count++; 105 | } 106 | if(a->arr[mid-i] == a->arr[mid] || mid-i >= 0){ 107 | count++; 108 | } 109 | i+=1; 110 | }while(a->arr[mid+i] == a->arr[mid] || a->arr[mid-i] == a->arr[mid]); 111 | 112 | printf("\t%d is repeted %d times..\n\n",a->arr[mid],count+1); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /All Data Structure/Double Linked List/Double Linked List.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node 5 | { 6 | int data; 7 | struct node *lptr,*rptr; 8 | }; 9 | struct node* createNode(int x) 10 | { 11 | struct node *temp; 12 | temp=(struct node*)malloc(sizeof(struct node)); 13 | temp->data=x; 14 | return temp; 15 | } 16 | void insert(struct node *header, int x) 17 | { 18 | struct node *temp,*p; 19 | temp=createNode(x); 20 | p=header->rptr; 21 | temp->rptr=header->rptr; 22 | header->rptr=temp; 23 | temp->lptr=header; 24 | if(p!=NULL) 25 | p->lptr=temp; 26 | } 27 | void display(struct node *header) 28 | { 29 | struct node *ptr,*end; 30 | ptr=header->rptr; 31 | printf("\n"); 32 | while(ptr!=NULL) 33 | { 34 | printf("%d ",ptr->data); 35 | end=ptr; 36 | ptr=ptr->rptr; 37 | } 38 | printf("\n"); 39 | } 40 | 41 | int search(struct node *header,int key) 42 | { 43 | struct node *ptr; 44 | ptr=header->rptr; 45 | while(ptr!=NULL) 46 | { 47 | if(ptr->data==key) 48 | return ptr->data; 49 | else 50 | ptr=ptr->rptr; 51 | } 52 | return -1; 53 | } 54 | 55 | void insertAfter(struct node *header,int key,int x) 56 | { 57 | struct node *ptr,*temp,*r; 58 | ptr=header->rptr; 59 | temp=createNode(x); 60 | while(ptr!=NULL) 61 | { 62 | if(ptr->data==key) 63 | { 64 | r=ptr->rptr; 65 | ptr->rptr=temp; 66 | temp->lptr=ptr; 67 | temp->rptr=r; 68 | r->lptr=temp; 69 | return ; 70 | } 71 | else 72 | ptr=ptr->rptr; 73 | } 74 | } 75 | void deleteE(struct node *header, int num) 76 | { 77 | struct node *ptr,*l,*r; 78 | ptr=header->rptr; 79 | while(ptr!=NULL) 80 | { 81 | if(ptr->data==num) 82 | { 83 | if(ptr->rptr == NULL){ 84 | ptr->lptr->rptr = NULL; 85 | return; 86 | } 87 | l=ptr->lptr; 88 | r=ptr->rptr; 89 | l->rptr=r; 90 | r->lptr=l; 91 | free(ptr); 92 | } 93 | else 94 | { 95 | ptr=ptr->rptr; 96 | } 97 | } 98 | } 99 | int main() 100 | { 101 | struct node *header; 102 | header=(struct node*)malloc(sizeof(struct node)); 103 | header->lptr=header->rptr=NULL; 104 | insert(header,10); 105 | insert(header,20); 106 | insert(header,30); 107 | insert(header,40); 108 | insert(header,50); 109 | display(header); 110 | deleteE(header,10); 111 | insertAfter(header,30,100); 112 | display(header); 113 | 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /Assignment-7/avlADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | struct avltree{ 7 | char data; 8 | struct avltree *left,*right; 9 | int height; 10 | }; 11 | 12 | int max(int a,int b){ 13 | if(a>b){ 14 | return a; 15 | } 16 | else{ 17 | return b; 18 | } 19 | } 20 | 21 | int h(struct avltree *t){ 22 | if(t==NULL){ 23 | return -1; 24 | } 25 | else{ 26 | return t->height; 27 | } 28 | } 29 | struct avltree *singlerotatewithleft(struct avltree *k2){ 30 | struct avltree *k1; 31 | k1=k2->left; 32 | k2->left=k1->right; 33 | k1->right=k2; 34 | k1->height=max(h(k1->left),h(k1->right))+1; 35 | k2->height=max(h(k2->left),h(k2->right))+1; 36 | return k1; 37 | } 38 | 39 | struct avltree *singlerotatewithright(struct avltree *k2){ 40 | struct avltree *k1; 41 | k1=k2->right; 42 | k2->right=k1->left; 43 | k1->left=k2; 44 | k1->height=max(h(k1->left),h(k1->right))+1; 45 | k2->height=max(h(k2->left),h(k2->right))+1; 46 | return k1; 47 | } 48 | 49 | struct avltree *doublerotatewithleft(struct avltree *k1){ 50 | k1->left=singlerotatewithright(k1->left); 51 | return singlerotatewithleft(k1); 52 | } 53 | 54 | struct avltree *doublerotatewithright(struct avltree *k1){ 55 | k1->right=singlerotatewithleft(k1->right); 56 | return singlerotatewithright(k1); 57 | } 58 | 59 | struct avltree *insert(struct avltree *t,char x){ 60 | if(t==NULL){ 61 | struct avltree *temp; 62 | temp=(struct avltree *)malloc(sizeof(struct avltree)); 63 | temp->data = x; 64 | temp->left=temp->right=NULL; 65 | temp->height=0; 66 | return temp; 67 | } 68 | 69 | else if(xdata){ 70 | t->left=insert(t->left,x); 71 | if(abs(h(t->left)-h(t->right))==2){ 72 | if(x<(t->left)->data){ 73 | t=singlerotatewithleft(t); 74 | } 75 | else{ 76 | t=doublerotatewithleft(t); 77 | } 78 | } 79 | } 80 | 81 | else if(x>t->data){ 82 | t->right=insert(t->right,x); 83 | if(abs(h(t->right)-h(t->left))==2){ 84 | if(x>t->data){ 85 | t=singlerotatewithright(t); 86 | } 87 | else{ 88 | t=doublerotatewithright(t); 89 | } 90 | } 91 | } 92 | t->height=max(h(t->left),h(t->right))+1; 93 | 94 | return t; 95 | } 96 | 97 | void inorder(struct avltree *t){ 98 | if(t==NULL){ 99 | return; 100 | } 101 | inorder(t->left); 102 | printf("%c ",t->data); 103 | inorder(t->right); 104 | } 105 | -------------------------------------------------------------------------------- /All Data Structure/Circular Linked List/ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | 9 | void insert(struct node *h, int data){ 10 | struct node *temp = (struct node *) malloc(sizeof(struct node)); 11 | temp->data = data; 12 | if(h->next == NULL){ 13 | temp->next = h; 14 | h->next = temp; 15 | } 16 | else { 17 | temp->next = h->next; 18 | h->next = temp; 19 | } 20 | } 21 | 22 | int length(struct node *h){ 23 | struct node *ptr = h->next; 24 | int len =0; 25 | while (ptr != h) 26 | { 27 | len++; 28 | ptr = ptr->next; 29 | } 30 | return len; 31 | } 32 | 33 | void add(struct node *h, int data){ 34 | struct node *temp = (struct node *) malloc(sizeof(struct node)); 35 | temp->data = data; 36 | if(h->next == NULL){ 37 | temp->next = h; 38 | h->next = temp; 39 | return ; 40 | } 41 | struct node *ptr; 42 | ptr = h->next; 43 | for(int i =0; inext; 45 | } 46 | temp->next = ptr->next; 47 | ptr->next = temp; 48 | } 49 | 50 | void display(struct node *h){ 51 | struct node *ptr = h->next; 52 | while (ptr != h) 53 | { 54 | printf("%d ",ptr->data); 55 | ptr = ptr->next; 56 | } 57 | printf("\n"); 58 | } 59 | 60 | void delete(struct node *h){ 61 | struct node *temp = h->next; 62 | h->next = h->next->next; 63 | free(temp); 64 | } 65 | void deletePos(struct node *header, int key) 66 | { 67 | 68 | struct node *ptr = header->next,*temp; 69 | temp = header->next; 70 | 71 | if(temp->data == key) { 72 | header->next = header->next->next; 73 | return; 74 | } 75 | while(ptr!=NULL){ 76 | if(ptr->data == key){ 77 | temp->next=ptr->next; 78 | free(ptr); 79 | return; 80 | } 81 | else{ 82 | temp = ptr; 83 | ptr = ptr->next; 84 | 85 | } 86 | } 87 | } 88 | void sortL(struct node *head){ 89 | int i=0, j=0, len = length(head); 90 | struct node *temp1=head->next, *temp = head->next; 91 | for(i=0; idata < temp->data){ 94 | int T = temp1->data; 95 | temp1->data = temp->data; 96 | temp->data = T; 97 | } 98 | temp = temp->next; 99 | } 100 | temp1 = temp1->next; 101 | temp = head->next; 102 | } 103 | } 104 | 105 | void reverseList(struct node *h) { 106 | struct node *ptr, *after, *prev, *last; 107 | prev=h->next; 108 | last=prev; 109 | ptr=prev->next; 110 | while(ptr->next!=h) 111 | { 112 | after=ptr->next; 113 | ptr->next=prev; 114 | prev=ptr; 115 | ptr=after; 116 | } 117 | ptr->next=prev; 118 | h->next=ptr; 119 | last->next=h; 120 | } 121 | -------------------------------------------------------------------------------- /All Data Structure/AVL/avlADT.h: -------------------------------------------------------------------------------- 1 | #define MAX(a,b) ( (a) > (b) ? (a) : (b) ) 2 | 3 | 4 | struct avl{ 5 | int data,h; 6 | struct avl *left,*right; 7 | }; 8 | 9 | int height(struct avl *t){ 10 | if(t == NULL) return -1; 11 | return t->h; 12 | } 13 | 14 | 15 | struct avl * singleleft(struct avl *t){ 16 | struct avl *temp; 17 | 18 | temp = t->left; 19 | t->left = temp->right; 20 | temp->right = t; 21 | 22 | temp->h = MAX(height(temp->left),height(temp->right)) + 1; 23 | t->h = MAX(height(t->left), height(t->right) )+1; 24 | 25 | return temp; 26 | } 27 | 28 | 29 | struct avl * singleright(struct avl *t){ 30 | struct avl *temp; 31 | 32 | temp = t->right; 33 | t->right = temp->left; 34 | temp->left = t; 35 | 36 | temp->h = MAX(height(temp->left),height(temp->right)) + 1; 37 | t->h = MAX(height(t->left), height(t->right) )+1; 38 | 39 | return temp; 40 | } 41 | 42 | struct avl * doubleright_left(struct avl *t){ 43 | t->left = singleright(t->left); 44 | return singleleft(t); 45 | } 46 | struct avl * doubleleft_right(struct avl *t){ 47 | t->right = singleleft(t->right); 48 | return singleright(t); 49 | } 50 | 51 | 52 | struct avl * Insert(struct avl *t, int x){ 53 | if(t == NULL){ 54 | struct avl *temp = (struct avl *) malloc(sizeof(struct avl)); 55 | temp->data = x; 56 | temp->left = temp->right = NULL; 57 | temp->h = 0; 58 | return temp; 59 | } 60 | else if(x < t->data){ 61 | t->left = Insert(t->left,x); 62 | if(abs(height(t->left) - height(t->right)) == 2){ 63 | if(x < t->left->data) 64 | t = singleleft(t); 65 | else 66 | t = doubleright_left(t); 67 | } 68 | } 69 | else if(x > t->data){ 70 | t->right = Insert(t->right,x); 71 | if(abs(height(t->left) - height(t->right)) == 2){ 72 | if(x < t->right->data) 73 | t = singleright(t); 74 | else 75 | t = doubleleft_right(t); 76 | } 77 | } 78 | 79 | t->h = MAX(height(t->left), height(t->right))+1; 80 | return t; 81 | 82 | } 83 | 84 | void inorder(struct avl *t){ 85 | if(t->left != NULL) 86 | inorder(t->left); 87 | printf("%d %d\n",t->data,t->h); 88 | if(t->right != NULL) 89 | inorder(t->right); 90 | } 91 | 92 | void printGivenLevel(struct avl* root, int level) { 93 | if (root == NULL) 94 | return; 95 | if (level == 1) 96 | printf("%d ", root->data); 97 | else if (level > 1) { 98 | printGivenLevel(root->left, level-1); 99 | printGivenLevel(root->right, level-1); 100 | } 101 | } 102 | 103 | 104 | void levelOrderTraversal(struct avl* root) { 105 | int h = height(root)+1; 106 | int i; 107 | for (i=1; i<=h; i++){ 108 | printGivenLevel(root, i); 109 | printf("\n"); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /Assignment-9/graph.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Queue.h" 4 | #include "Stack.h" 5 | 6 | struct graph{ 7 | int vertex; 8 | int edges; 9 | int **adj; 10 | char data[100][20]; 11 | }; 12 | 13 | struct graph* create_graph(){ 14 | int i,j,k,data; 15 | struct graph *g; 16 | g = (struct graph *) malloc(sizeof(struct graph)); 17 | printf("Enter the number of Nodes and Edges (N,E) : "); 18 | scanf("%d %d",&g->vertex,&g->edges); 19 | g->adj = (int **) malloc(g->vertex * sizeof(int)); 20 | g->adj[0] = (int *) malloc(g->vertex * sizeof(int)); 21 | 22 | for(i=0; ivertex; i++){ 23 | g->adj[i] = (int *) malloc(g->vertex * sizeof(int)); 24 | for(j=0; jvertex; j++) 25 | g->adj[i][j] = 0; 26 | } 27 | printf("Enter the nodes in pair (a -> b) \n"); 28 | for(i=0; iedges; i++){ 29 | scanf("%d",&j); 30 | scanf("%d",&k); 31 | g->adj[j-1][k-1] = 1; 32 | } 33 | printf("Enter the all data : \n"); 34 | for(int i=0; ivertex; i++) 35 | scanf("%s",g->data[i]); 36 | return g; 37 | } 38 | 39 | void displayadj(struct graph *g){ 40 | int u,v; 41 | printf("Adj : matrix \n"); 42 | for(u=0; uvertex; u++){ 43 | for(v=0; vvertex; v++) 44 | printf("%d ",g->adj[u][v]); 45 | printf("\n"); 46 | } 47 | } 48 | 49 | void BFS(struct graph *g, int start){ 50 | 51 | int i=0,visit[g->vertex]; 52 | for(i=0; ivertex; i++) visit[i]=0; 53 | struct queue *q = createQueue(20); 54 | printf("\n\n"); 55 | printf("BFS : "); 56 | start--; 57 | printf("%s --> ",g->data[start]); 58 | visit[start] = 1; 59 | enqueue(q,start); 60 | while (!isEmpty(q)) 61 | { 62 | int deq = dequeue(q); 63 | for(i=0; ivertex; i++){ 64 | if(g->adj[deq][i] == 1 && visit[i]==0){ 65 | printf("%s --> ",g->data[i]); 66 | visit[i] = 1; 67 | enqueue(q,i); 68 | } 69 | } 70 | } 71 | printf("*\n\n"); 72 | } 73 | /* 74 | Test case 1 75 | 7 6 76 | 1 2 77 | 1 3 78 | 2 4 79 | 2 5 80 | 3 6 81 | 3 7 82 | A 83 | B 84 | C 85 | D 86 | E 87 | F 88 | G 89 | 90 | */ 91 | 92 | /* 93 | Test case 2 94 | 6 7 95 | 1 2 96 | 2 3 97 | 2 4 98 | 4 5 99 | 5 6 100 | 3 6 101 | 3 1 102 | 1 103 | 2 104 | 3 105 | 4 106 | 5 107 | 6 108 | 109 | 110 | */ 111 | 112 | /* 113 | Test case 3 114 | 6 7 115 | 1 6 116 | 6 2 117 | 6 5 118 | 5 4 119 | 4 3 120 | 2 3 121 | 2 1 122 | Chennai 123 | Oouty 124 | Selam 125 | Ambur 126 | Theni 127 | Maduri 128 | 129 | 130 | */ 131 | 132 | void DFS(struct graph *g, int start){ 133 | int i=0,visit[g->vertex]; 134 | for(i=0; ivertex; i++) visit[i]=0; 135 | start--; 136 | struct stack *s = createStack(20); 137 | printf("%s --> ",g->data[start]); 138 | visit[start] = 1; 139 | push(s,start); 140 | while (!isEmptystack(s)) 141 | { 142 | int top = gettop(s),flag=0; 143 | for(i=0; ivertex; i++){ 144 | if(g->adj[top][i] == 1 && visit[i]==0){ 145 | flag=1; 146 | break; 147 | } 148 | } 149 | if(flag){ 150 | printf("%s --> ",g->data[i]); 151 | visit[i] = 1; 152 | push(s,i); 153 | } 154 | else pop(s); 155 | } 156 | printf("*\n\n"); 157 | 158 | } 159 | 160 | 161 | 162 | /* 163 | 7 7 164 | 1 2 165 | 1 3 166 | 3 2 167 | 3 4 168 | 4 5 169 | 4 7 170 | 6 5 171 | 1 172 | 2 173 | 3 174 | 4 175 | 5 176 | 6 177 | 7 178 | 179 | 180 | */ -------------------------------------------------------------------------------- /All Data Structure/GRAPH/graph.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"Queue.h" 4 | #include "Stack.h" 5 | 6 | struct graph{ 7 | int vertex; 8 | int edges; 9 | int **adj; 10 | char data[100][20]; 11 | }; 12 | 13 | struct graph* create_graph(){ 14 | int i,j,k,data; 15 | struct graph *g; 16 | g = (struct graph *) malloc(sizeof(struct graph)); 17 | printf("Enter the number of Nodes and Edges (N,E) : "); 18 | scanf("%d %d",&g->vertex,&g->edges); 19 | g->adj = (int **) malloc(g->vertex * sizeof(int)); 20 | g->adj[0] = (int *) malloc(g->vertex * sizeof(int)); 21 | 22 | for(i=0; ivertex; i++){ 23 | g->adj[i] = (int *) malloc(g->vertex * sizeof(int)); 24 | for(j=0; jvertex; j++) 25 | g->adj[i][j] = 0; 26 | } 27 | printf("Enter the nodes in pair (a -> b) \n"); 28 | for(i=0; iedges; i++){ 29 | scanf("%d",&j); 30 | scanf("%d",&k); 31 | g->adj[j-1][k-1] = 1; 32 | } 33 | printf("Enter the all data : \n"); 34 | for(int i=0; ivertex; i++) 35 | scanf("%s",g->data[i]); 36 | return g; 37 | } 38 | 39 | void displayadj(struct graph *g){ 40 | int u,v; 41 | printf("Adj : matrix \n"); 42 | for(u=0; uvertex; u++){ 43 | for(v=0; vvertex; v++) 44 | printf("%d ",g->adj[u][v]); 45 | printf("\n"); 46 | } 47 | } 48 | 49 | void BFS(struct graph *g, int start){ 50 | 51 | int i=0,visit[g->vertex]; 52 | for(i=0; ivertex; i++) visit[i]=0; 53 | struct queue *q = createQueue(20); 54 | printf("\n\n"); 55 | printf("BFS : "); 56 | start--; 57 | printf("%s --> ",g->data[start]); 58 | visit[start] = 1; 59 | enqueue(q,start); 60 | while (!isEmpty(q)) 61 | { 62 | int deq = dequeue(q); 63 | for(i=0; ivertex; i++){ 64 | if(g->adj[deq][i] == 1 && visit[i]==0){ 65 | printf("%s --> ",g->data[i]); 66 | visit[i] = 1; 67 | enqueue(q,i); 68 | } 69 | } 70 | } 71 | printf("*\n\n"); 72 | } 73 | 74 | void DFS(struct graph *g, int start){ 75 | int i=0,visit[g->vertex]; 76 | for(i=0; ivertex; i++) visit[i]=0; 77 | start--; 78 | struct stack *s = createStack(20); 79 | printf("%s --> ",g->data[start]); 80 | visit[start] = 1; 81 | push(s,start); 82 | while (!isEmptystack(s)) 83 | { 84 | int top = gettop(s),flag=0; 85 | for(i=0; ivertex; i++){ 86 | if(g->adj[top][i] == 1 && visit[i]==0){ 87 | flag=1; 88 | break; 89 | } 90 | } 91 | if(flag){ 92 | printf("%s --> ",g->data[i]); 93 | visit[i] = 1; 94 | push(s,i); 95 | } 96 | else pop(s); 97 | } 98 | printf("*\n\n"); 99 | 100 | } 101 | 102 | 103 | /* 104 | Test case 1 105 | 7 6 106 | 1 2 107 | 1 3 108 | 2 4 109 | 2 5 110 | 3 6 111 | 3 7 112 | A 113 | B 114 | C 115 | D 116 | E 117 | F 118 | G 119 | 120 | */ 121 | 122 | /* 123 | Test case 2 124 | 6 7 125 | 1 2 126 | 2 3 127 | 2 4 128 | 4 5 129 | 5 6 130 | 3 6 131 | 3 1 132 | 1 133 | 2 134 | 3 135 | 4 136 | 5 137 | 6 138 | 139 | 140 | */ 141 | 142 | /* 143 | Test case 3 144 | 6 7 145 | 1 6 146 | 6 2 147 | 6 5 148 | 5 4 149 | 4 3 150 | 2 3 151 | 2 1 152 | Chennai 153 | Oouty 154 | Selam 155 | Ambur 156 | Theni 157 | Maduri 158 | 159 | 160 | */ 161 | 162 | 163 | /* 164 | 7 7 165 | 1 2 166 | 1 3 167 | 3 2 168 | 3 4 169 | 4 5 170 | 4 7 171 | 6 5 172 | 1 173 | 2 174 | 3 175 | 4 176 | 5 177 | 6 178 | 7 179 | 180 | 181 | */ -------------------------------------------------------------------------------- /Assignment-10/dijsktrasgraph.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | struct graph{ 6 | int vertex; 7 | int edges; 8 | int **adj; 9 | char **data; 10 | }; 11 | 12 | struct graph* create_graph(){ 13 | int u,v,i,data; 14 | struct graph *g; 15 | g = (struct graph *) malloc(sizeof(struct graph)); 16 | printf("Enter the number of Nodes and Edges (N,E) : "); 17 | scanf("%d %d",&g->vertex,&g->edges); 18 | g->adj = (int **) malloc(g->vertex * sizeof(int)); 19 | g->data = (char **) malloc(g->vertex * sizeof(char)); 20 | g->data[0] = (char *) malloc(5 * sizeof(char)); 21 | 22 | 23 | // adj matrix 24 | for(u=0; uvertex; u++){ 25 | g->adj[u] = (int *) malloc(g->vertex * sizeof(int)); 26 | for(v=0; vvertex; v++){ 27 | g->adj[u][v] = 0; 28 | } 29 | } 30 | printf("Enter the nodes in pair (a -> b) \n"); 31 | for(i=0; iedges; i++){ 32 | scanf("%d %d %d",&u,&v,&data); 33 | g->adj[u-1][v-1] = data; 34 | } 35 | printf("Enter the All Data :- \n"); 36 | for(i=0; ivertex; i++){ 37 | g->data[i] = (char *) malloc(5 * sizeof(char)); 38 | printf("Enter the data %d : ",i+1); 39 | scanf("%s ",g->data[i]); 40 | } 41 | return g; 42 | } 43 | 44 | void displayadj(struct graph *g){ 45 | int u,v; 46 | printf("Adj : matrix \n"); 47 | for(u=0; uvertex; u++){ 48 | for(v=0; vvertex; v++){ 49 | printf("%d ",g->adj[u][v]); 50 | } 51 | printf("\n"); 52 | } 53 | printf("\nData : matrix \n"); 54 | for(u=0; uvertex; u++){ 55 | printf("%s ",g->data[u]); 56 | } 57 | } 58 | 59 | int min(struct graph *gr, int **distance, int sptSet[]) 60 | { 61 | int min = 999999, min_index; 62 | 63 | for (int v = 0; v < gr->vertex; v++) 64 | if (sptSet[v] == 0 && distance[1][v] <= min) 65 | min = distance[1][v], min_index = v; 66 | 67 | return min_index; 68 | } 69 | void displayTable(struct graph *gr, int **distance) 70 | { 71 | printf("Vertex -> distanceance\n"); 72 | for (int i = 0; i < gr->vertex; i++) 73 | printf(" %d) %s ---> %d --> %s\n", i+1, gr->data[i], distance[1][i], gr->data[distance[2][i]]); 74 | } 75 | int** dijkstra(struct graph *gr, int src) 76 | { 77 | int **graph = gr->adj; 78 | int **distance = (int**) malloc(4 * sizeof(int)); 79 | distance[0] = (int*) malloc(gr->vertex * sizeof(int)); 80 | distance[1] = (int*) malloc(gr->vertex * sizeof(int)); 81 | distance[2] = (int*) malloc(gr->vertex * sizeof(int)); 82 | 83 | int sptSet[gr->vertex]; 84 | 85 | for (int i = 0; i < gr->vertex; i++){ 86 | distance[0][i] = i; 87 | distance[1][i] = 99999, sptSet[i] = 0; 88 | } 89 | // printf("\t%d,%d %s\n",u,v,gr->data[src]); 90 | distance[1][src] = 0; 91 | for (int count = 0; count < gr->vertex - 1; count++) { 92 | int u = min(gr, distance, sptSet); 93 | sptSet[u] = 1; 94 | for (int v = 0; v < gr->vertex; v++){ 95 | if (!sptSet[v] && graph[u][v] && distance[1][u] != 999999 && distance[1][u] + graph[u][v] < distance[1][v]){ 96 | distance[1][v] = distance[1][u] + graph[u][v]; 97 | distance[2][v] = u; 98 | } 99 | } 100 | distance[2][src] = -1; 101 | distance[1][src] = -1; 102 | displayTable(gr,distance); 103 | printf("\n"); 104 | } 105 | return distance; 106 | } 107 | 108 | void printPath(struct graph *g, int **table,int start){ 109 | if(table[1][start] != -1){ 110 | printPath(g,table,table[2][start]); 111 | printf(" to "); 112 | } 113 | printf("%s ",g->data[start]); 114 | } 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /Assignment-5/ADT.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct tree{ 5 | int data; 6 | struct tree *left; 7 | struct tree *right; 8 | }; 9 | struct tree *insert(struct tree *t,int x) 10 | { 11 | if (t==NULL) 12 | { 13 | t=(struct tree*)malloc(sizeof(struct tree)); 14 | t->data=x; 15 | t->left=NULL; 16 | t->right=NULL; 17 | } 18 | else if(x>t->data) 19 | { 20 | t->right=insert(t->right,x); 21 | } 22 | else 23 | { 24 | t->left=insert(t->left,x); 25 | } 26 | return t; 27 | } 28 | void inorder(struct tree *t) 29 | { 30 | if (t->left!=NULL){ 31 | inorder(t->left); 32 | } 33 | printf("%d,",t->data); 34 | if(t->right!=NULL){ 35 | inorder(t->right); 36 | } 37 | } 38 | void preorder(struct tree *t) 39 | { 40 | printf("%d,",t->data); 41 | if (t->left!=NULL){ 42 | preorder(t->left); 43 | } 44 | if(t->right!=NULL){ 45 | preorder(t->right); 46 | } 47 | } 48 | void postorder(struct tree *t) 49 | { 50 | if (t->left!=NULL){ 51 | postorder(t->left); 52 | } 53 | if(t->right!=NULL){ 54 | postorder(t->right); 55 | } 56 | printf("%d,",t->data); 57 | } 58 | struct tree *findMin(struct tree *t) 59 | { 60 | if(t->left!=NULL){ 61 | return findMin(t->left); 62 | } 63 | return t; 64 | } 65 | struct tree *findMax(struct tree *t) 66 | { 67 | if(t->right!=NULL){ 68 | return findMax(t->right); 69 | } 70 | return t; 71 | } 72 | struct tree *search(struct tree *t,int x) 73 | { 74 | if(t==NULL){ 75 | return NULL; 76 | } 77 | else if (x==t->data){ 78 | return t; 79 | } 80 | else if(x>t->data){ 81 | return search(t->right,x); 82 | } 83 | else{ 84 | return search(t->left,x); 85 | } 86 | } 87 | struct tree *delete(struct tree *t,int x) 88 | { 89 | if(t==NULL) 90 | return t; 91 | else if(x>t->data){ 92 | t->right=delete(t->right,x); 93 | } 94 | else if(xdata){ 95 | t->left=delete(t->left,x); 96 | } 97 | else{ 98 | struct tree *temp; 99 | if(t->left==NULL && t->right==NULL){ 100 | free(t); 101 | return NULL; 102 | } 103 | else if(t->left==NULL){ 104 | temp=t; 105 | t=t->right; 106 | free(temp); 107 | 108 | } 109 | else if(t->right==NULL){ 110 | struct tree *temp; 111 | temp=t; 112 | t=t->left; 113 | free(temp); 114 | } 115 | else{ 116 | struct tree *min; 117 | min=findMin(t->right); 118 | t->data=min->data; 119 | t->right=delete(t->right,min->data); 120 | } 121 | } 122 | return t; 123 | } 124 | // Online code 125 | int height(struct tree* h) 126 | { 127 | if (h == NULL) 128 | return 0; 129 | else { 130 | int lheight = height(h->left); 131 | int rheight = height(h->right); 132 | 133 | if (lheight > rheight) 134 | return (lheight + 1); 135 | else 136 | return (rheight + 1); 137 | } 138 | } 139 | void printCurrentLevel(struct tree* h, int level) 140 | { 141 | if (h == NULL) 142 | return; 143 | if (level == 1) 144 | printf("%d ", h->data); 145 | else if (level > 1) { 146 | printCurrentLevel(h->left, level - 1); 147 | printCurrentLevel(h->right, level - 1); 148 | } 149 | } 150 | void levelOrder(struct tree* h) 151 | { 152 | int hei = height(h); 153 | int i,j=1; 154 | for (i = 1; i <= hei; i++){ 155 | printf("\nLevel %d : ",j++); 156 | printCurrentLevel(h,i); 157 | } 158 | } 159 | // online code end. 160 | -------------------------------------------------------------------------------- /All Data Structure/README.md: -------------------------------------------------------------------------------- 1 | # Linear Data Structure 2 | ### 1. [Array Data Structure](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Array%20Data%20Structure)
3 | -> create(arrADT, Size, arr); 4 | -> insert(arrADT, data); 5 | -> insertPos(arrADT, pos, data); 6 | -> insertLast(arADT, data); 7 | -> length(arrADT); 8 | -> display(arrADT); 9 | 10 | ### 2. [Simple Lnked List](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Simple%20Linked%20List)
11 | -> insert(head, data); 12 | -> insertPos(head, pos, data); 13 | -> insertLast(head, data); 14 | -> delete(head); 15 | -> deletePos(head, pos); 16 | -> deleteData(head, data); 17 | -> deleteLast(head); 18 | -> display(head); 19 | -> length(head); 20 | 21 | ### 3. [Circle Linked List](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Circular%20Linked%20List)
22 | -> insert(head, data); 23 | -> insertPos(head, pos, data); 24 | -> insertLast(head, data); 25 | -> delete(head); 26 | -> deletePos(head, pos); 27 | -> deleteData(head, data); 28 | -> deleteLast(head); 29 | -> display(head); 30 | -> length(head); 31 | 32 | ### 4. [Double Linked List](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Double%20Linked%20List)
33 | -> insert(head, data); 34 | -> insertPos(head, pos, data); 35 | -> insertLast(head, data); 36 | -> delete(head); 37 | -> deletePos(head, pos); 38 | -> deleteData(head, data); 39 | -> deleteLast(head); 40 | -> display(head); 41 | -> length(head); 42 | 43 | ### 5. [Stack using array implementation](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Stack%20using%20array%20implementation)
44 | -> createStack(lim); 45 | -> push(S, data); 46 | -> pop(S); 47 | -> displayStack(S); 48 | -> gettop(S); 49 | -> isEmpty(S); 50 | -> isFill(S); 51 | 52 | ### 6. [Queue using array implementation](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Queue%20using%20array%20implementation)
53 | -> createQueue(lim); 54 | -> enqueue(Q, data); 55 | -> dequeue(Q); 56 | -> displayQueue(Q); 57 | -> isEmpty(Q); 58 | -> isFill(Q); 59 | 60 | ### 7. [Binary Search Tree](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/BST)
61 | -> insertBST(T, data); 62 | -> deleteBST(T); 63 | -> inorderBST(T); 64 | -> levelorderBST(T); 65 | -> findmax(T); 66 | 67 | ### 8. [AVL Tree](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/AVL)
68 | -> Insert(T, data); 69 | -> delete(T); 70 | -> inorderBST(T); 71 | -> levelOrderTraversal(T); 72 | -> singleright(T); 73 | -> doubleleft_right(T); 74 | -> singleleft(T); 75 | -> doubleright_left(T); 76 | 77 | ### 9. [Priarity_Queue or Min Heap](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Priarity_Queue)
78 | -> PriarityQueueCreate(T); 79 | -> Insert(T, data); 80 | -> delete(T); 81 | -> Display(T); 82 | 83 | ### 10. [Graph](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/GRAPH)
84 | -> CreateGraph(G); 85 | -> displayadj(G); 86 | -> BFS(G); 87 | -> DFS(G); 88 | 89 | 90 | ### 11. [Graph Algorithms](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/GRAPH%20Appliactions)
91 | #### Dijkstra(Shortest paths Algo) 92 | -> dijkstra(G, src); 93 | -> printPath(G, table, des); 94 | -> displayTable(g, table); 95 | -> min(G, table, visit); 96 | #### Floyd–Warshall algorithms(All pair-Shortest paths Algo) 97 | -> Floyd_Warshall(G,tablel); 98 | -> printPath(G, table, des); 99 | -> display_Pre_Matrix(g, table); 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Tutorial-3/State_Capital_application.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct tree{ 5 | char state[20]; 6 | char capital[20]; 7 | struct tree *left; 8 | struct tree *right; 9 | }; 10 | struct tree *insert(struct tree *t,char x[],char c[]) 11 | { 12 | if (t==NULL) 13 | { 14 | t=(struct tree*)malloc(sizeof(struct tree)); 15 | strcpy(t->state,x); 16 | strcpy(t->capital,c); 17 | t->left=NULL; 18 | t->right=NULL; 19 | } 20 | else if(strcmp(x,t->state)>0) 21 | { 22 | t->right=insert(t->right,x,c); 23 | } 24 | else 25 | { 26 | t->left=insert(t->left,x,c); 27 | } 28 | return t; 29 | } 30 | void inorder(struct tree *t) 31 | { 32 | if (t->left!=NULL){ 33 | inorder(t->left); 34 | } 35 | printf(" %s - %s ,",t->state,t->capital); 36 | if(t->right!=NULL){ 37 | inorder(t->right); 38 | } 39 | } 40 | 41 | struct tree *findMin(struct tree *t) 42 | { 43 | if(t->left!=NULL){ 44 | return findMin(t->left); 45 | } 46 | return t; 47 | } 48 | 49 | struct tree *search(struct tree *t,char x[]) 50 | { 51 | if(t==NULL){ 52 | return NULL; 53 | } 54 | else if (strcmp(x,t->state)==0){ 55 | return t; 56 | } 57 | else if(strcmp(x,t->state)>0){ 58 | return search(t->right,x); 59 | } 60 | else{ 61 | return search(t->left,x); 62 | } 63 | } 64 | 65 | struct tree *delete(struct tree *t,char s[]) 66 | { 67 | if(t==NULL) 68 | return t; 69 | else if(strcmp(s,t->state)>0){ 70 | t->right=delete(t->right,s); 71 | } 72 | else if(strcmp(s,t->state)<0){ 73 | t->left=delete(t->left,s); 74 | } 75 | else{ 76 | struct tree *temp; 77 | if(t->left==NULL && t->right==NULL){ 78 | free(t); 79 | return NULL; 80 | } 81 | else if(t->left==NULL){ 82 | temp=t; 83 | t=t->right; 84 | free(temp); 85 | 86 | } 87 | else if(t->right==NULL){ 88 | struct tree *temp; 89 | temp=t; 90 | t=t->left; 91 | free(temp); 92 | } 93 | else{ 94 | struct tree *min; 95 | min=findMin(t->right); 96 | strcpy(t->state,min->state); 97 | t->right=delete(t->right,min->state); 98 | } 99 | } 100 | return t; 101 | } 102 | 103 | void main(){ 104 | struct tree *t,*sea; 105 | t=NULL; 106 | int choice,op; 107 | char state[20],capital[20]; 108 | printf("1 For insert state and capital\n2 Delete the State\n3 For Search the state for capital\n4 For Inorder the tree\n"); 109 | do{ 110 | printf("Enter your option: "); 111 | scanf("%d",&op); 112 | switch(op){ 113 | case 1:printf("Enter the state for insert: "); 114 | scanf("%s",state); 115 | printf("Enter the capital for insert: "); 116 | scanf("%s",capital); 117 | t=insert(t,state,capital); 118 | break; 119 | case 2:printf("Enter the state for delete: "); 120 | scanf("%s",state); 121 | t=delete(t,state); 122 | break; 123 | case 3:printf("Enter the state for find its capital: "); 124 | scanf("%s",state); 125 | sea=search(t,state); 126 | if(sea!=NULL){ 127 | printf("\nThe State is Found and the capital of %s is %s\n",sea->state,sea->capital); 128 | } 129 | else{ 130 | printf("\nThe element is not found"); 131 | } 132 | break; 133 | case 4:printf("Inorder : "); 134 | inorder(t); 135 | printf("\n"); 136 | } 137 | printf("Do you want to continue means enter 1 else Enter 0: "); 138 | scanf("%d",&choice); 139 | }while(choice==1); 140 | } 141 | -------------------------------------------------------------------------------- /All Data Structure/GRAPH Appliactions/graph.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct graph{ 4 | int vertex; 5 | int edges; 6 | int **adj; 7 | char data[100][20]; 8 | }; 9 | 10 | struct graph* create_graph(){ 11 | int i,j,k,data; 12 | struct graph *g; 13 | g = (struct graph *) malloc(sizeof(struct graph)); 14 | printf("Enter the number of Nodes and Edges (N,E) : "); 15 | scanf("%d %d",&g->vertex,&g->edges); 16 | g->adj = (int **) malloc(g->vertex * sizeof(int)); 17 | g->adj[0] = (int *) malloc(g->vertex * sizeof(int)); 18 | 19 | for(i=0; ivertex; i++){ 20 | g->adj[i] = (int *) malloc(g->vertex * sizeof(int)); 21 | for(j=0; jvertex; j++) 22 | g->adj[i][j] = 0; 23 | } 24 | printf("Enter the nodes in pair (a -> b) \n"); 25 | for(i=0; iedges; i++){ 26 | scanf("%d",&j); 27 | scanf("%d",&k); 28 | g->adj[j-1][k-1] = 1; 29 | } 30 | printf("Enter the all data : \n"); 31 | for(int i=0; ivertex; i++) 32 | scanf("%s",g->data[i]); 33 | return g; 34 | } 35 | 36 | void displayadj(struct graph *g){ 37 | int u,v; 38 | printf("Adj : matrix \n"); 39 | for(u=0; uvertex; u++){ 40 | for(v=0; vvertex; v++) 41 | printf("%d ",g->adj[u][v]); 42 | printf("\n"); 43 | } 44 | } 45 | int min(struct graph *gr, int **distance, int sptSet[]) 46 | { 47 | int min = 999999, min_index; 48 | 49 | for (int v = 0; v < gr->vertex; v++) 50 | if (sptSet[v] == 0 && distance[1][v] <= min) 51 | min = distance[1][v], min_index = v; 52 | 53 | return min_index; 54 | } 55 | void displayTable(struct graph *gr, int **distance) 56 | { 57 | printf("Vertex -> distanceance\n"); 58 | for (int i = 0; i < gr->vertex; i++) 59 | printf(" %d) %s ---> %d --> %s\n", i+1, gr->data[i], distance[1][i], gr->data[distance[2][i]]); 60 | } 61 | int** dijkstra(struct graph *gr, int src) 62 | { 63 | int **graph = gr->adj; 64 | int **distance = (int**) malloc(4 * sizeof(int)); 65 | distance[0] = (int*) malloc(gr->vertex * sizeof(int)); 66 | distance[1] = (int*) malloc(gr->vertex * sizeof(int)); 67 | distance[2] = (int*) malloc(gr->vertex * sizeof(int)); 68 | 69 | int sptSet[gr->vertex]; 70 | 71 | for (int i = 0; i < gr->vertex; i++){ 72 | distance[0][i] = i; 73 | distance[1][i] = 99999, sptSet[i] = 0; 74 | } 75 | // printf("\t%d,%d %s\n",u,v,gr->data[src]); 76 | distance[1][src] = 0; 77 | for (int count = 0; count < gr->vertex - 1; count++) { 78 | int u = min(gr, distance, sptSet); 79 | sptSet[u] = 1; 80 | for (int v = 0; v < gr->vertex; v++){ 81 | if (!sptSet[v] && graph[u][v] && distance[1][u] != 999999 && distance[1][u] + graph[u][v] < distance[1][v]){ 82 | distance[1][v] = distance[1][u] + graph[u][v]; 83 | distance[2][v] = u; 84 | } 85 | } 86 | distance[2][src] = -1; 87 | distance[1][src] = -1; 88 | displayTable(gr,distance); 89 | printf("\n"); 90 | } 91 | return distance; 92 | } 93 | 94 | void printPath(struct graph *g, int **table,int start){ 95 | if(table[1][start] != -1){ 96 | printPath(g,table,table[2][start]); 97 | printf(" to "); 98 | } 99 | printf("%s ",g->data[start]); 100 | } 101 | 102 | 103 | /* 104 | Test case 1 105 | 7 6 106 | 1 2 107 | 1 3 108 | 2 4 109 | 2 5 110 | 3 6 111 | 3 7 112 | A 113 | B 114 | C 115 | D 116 | E 117 | F 118 | G 119 | 120 | */ 121 | 122 | /* 123 | Test case 2 124 | 6 7 125 | 1 2 126 | 2 3 127 | 2 4 128 | 4 5 129 | 5 6 130 | 3 6 131 | 3 1 132 | 1 133 | 2 134 | 3 135 | 4 136 | 5 137 | 6 138 | 139 | 140 | */ 141 | 142 | /* 143 | Test case 3 144 | 6 7 145 | 1 6 146 | 6 2 147 | 6 5 148 | 5 4 149 | 4 3 150 | 2 3 151 | 2 1 152 | Chennai 153 | Oouty 154 | Selam 155 | Ambur 156 | Theni 157 | Maduri 158 | 159 | 160 | */ 161 | 162 | 163 | /* 164 | 7 7 165 | 1 2 166 | 1 3 167 | 3 2 168 | 3 4 169 | 4 5 170 | 4 7 171 | 6 5 172 | 1 173 | 2 174 | 3 175 | 4 176 | 5 177 | 6 178 | 7 179 | 180 | 181 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data-Structure using C 2 | Graph and Sorting Algo : [link](https://github.com/KKBUGHUNTER/Data-Structure/blob/main/DS%20UNIT%204%2C5.pdf) 3 | 4 | 5 | ## Assignment 6 | 1. [Assignment 1](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment%201) Pointers & Array 7 | 2. [Assignment 2](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment%202) Linked List & **Applications** 8 | 3. [Assignment 3](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-3) Stack & **Applications** 9 | 4. [Assignment 4](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-4) Queue & **Applications** 10 | 5. [Assignment 5](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-5) BST & **Applications** 11 | 6. [Assignment 6](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-6) Double Linked List & **Applications** 12 | 7. [Assignment 7](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-7) AVL & **Applications** 13 | 8. [Assignment 8](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-8) Heap & **Applications** 14 | 9. [Assignment 9](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-9) BFS, DFS & **Applications** 15 | 10. [Assignment 10](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-10) dijsktras & **Applications** 16 | 11. [Assignment 11](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-11) Sorting & **Applications** 17 | 12. [Assignment 12](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Assignment-12) Hash Table & **Applications** 18 | 19 | 20 | 21 | ## Test 22 | 1. Assessment 1 in Array, List, Stack & Queue (MCQ) 23 | 2. Assessment 2 in ALL Trees (MCQ) 24 | 3. Assessment 3 in Binary Threaded Tree (MCQ with Self Study) 25 | 4. [Tutorial 1](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Tutorial-1) 26 | 5. [Tutorial 2](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Tutorial-2) 27 | 6. [Tutorial 3](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/Tutorial-3) 28 | 7. Assessment in Stack & Queue (Class Test - Algo Writing) 29 | 8. Assessment in Hash Table (Class Test - Algo Writing) 30 | 31 | 32 | 33 | ### List of Data Structure 34 | 1. [Array Data Structure](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Array%20Data%20Structure)
35 | 2. [Simple Lnked List](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Simple%20Linked%20List)
36 | 3. [Circle Linked List](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Circular%20Linked%20List)
37 | 4. [Double Linked List](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Double%20Linked%20List)
38 | 5. [Stack using array implementation](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Stack%20using%20array%20implementation)
39 | 6. [Queue using array implementation](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure)
40 | 7. [Binary Search Tree](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/BST)
41 | 8. [AVL Tree](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/AVL)
42 | 9. [Priarity_Queue or Min Heap](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/Priarity_Queue)
43 | 10. [Graph](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/GRAPH)
44 | 11. [Graph Algorithms](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/GRAPH%20Appliactions)
45 | - Dijkstra(Shortest paths Algo) 46 | - Floyd–Warshall algorithms(All pair-Shortest paths Algo) 47 | 12. [Sorting](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/GRAPH%20Appliactions) 48 | - Insertion Sort 49 | - Shell Sort 50 | - Radix Sort 51 | 13. [Hash Table](https://github.com/KKBUGHUNTER/Data-Structure/tree/main/All%20Data%20Structure/GRAPH%20Appliactions)
52 | 53 | 54 | 55 | ## Mini Project 56 | We have Done a Mini Project by **Solving CP Problems that related to above Data Structure.** This is a kind of Team project. 57 | 1. Karthikeyan 58 | 2. Mega 59 | 3. Irayanbu 60 | 61 | # ...Thank You... 62 | --------------------------------------------------------------------------------