From fa7a0da18eaae409d834193fd009ce3f34752073 Mon Sep 17 00:00:00 2001 From: Augustine S Aykara Date: Wed, 7 Nov 2018 19:51:30 +0530 Subject: [PATCH 1/2] added search function function to check whether element already exist or not in the binary tree --- searching/binaryTreeSearch.c | 65 ++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/searching/binaryTreeSearch.c b/searching/binaryTreeSearch.c index fb9eeef..952926e 100644 --- a/searching/binaryTreeSearch.c +++ b/searching/binaryTreeSearch.c @@ -3,11 +3,13 @@ #include #include + struct node { int data; struct node *lc, *rc; }*root = NULL; + struct node *createNode(int item) { struct node *n; @@ -20,6 +22,7 @@ struct node *createNode(int item) return n; } + void inorder(struct node *r) { struct node *ptr; @@ -33,19 +36,23 @@ void inorder(struct node *r) } } + + void preorder(struct node *r) { struct node *ptr; ptr = r; if(ptr != NULL) - { + { printf(" %d ", ptr -> data); preorder(ptr -> lc); preorder(ptr -> rc); } } + + void postorder(struct node *r) { struct node *ptr; @@ -54,12 +61,13 @@ void postorder(struct node *r) if(ptr != NULL) { postorder(ptr -> lc); - postorder(ptr -> rc); - printf(" %d ", ptr -> data); + postorder(ptr -> rc); + printf(" %d ", ptr -> data); } } + void insertion() { int item, flag = 0; @@ -108,18 +116,53 @@ void insertion() } } } - - printf("Inorder:"); + printf("\n"); + printf(" INORDER : "); inorder(root); printf("\n"); - printf("Preorder: "); + printf(" PREORDER : "); preorder(root); printf("\n"); - printf("Postorder: "); + printf(" POSTODER : "); postorder(root); printf("\n"); } + +void search() +{ + int ele, flag = 0; + struct node *ptr; + printf("\n Enter your element to be searched : "); + scanf("%d", &ele); + + ptr = root; + while (ptr != NULL && flag != 1) + { + if(ptr -> data < ele) + { + ptr = ptr -> rc; + } + else if(ptr -> data > ele) + { + ptr = ptr -> lc; + } + else + { + flag = 1; + printf("\n Element FOUND !!!!!! :) "); + break; + } + } + if (flag == 0) + { + printf("\n Element NOT FOUND !!!! :( "); + } + + printf("\n"); +} + + void main() { int ch; @@ -131,11 +174,11 @@ void main() switch(ch) { case 1: insertion(); - break; - //case 2: search(); - // break; + break; + case 2: search(); + break; case 3: exit(0); - break; + break; default : printf("\n INVALID CHOICE !!!! ;( "); } } From ab8ea4878172062c03a3555c64c82deea2054818 Mon Sep 17 00:00:00 2001 From: Augustine S Aykara Date: Wed, 7 Nov 2018 19:58:15 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7664163..db5cc89 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,14 @@ # Data-Structure-In-C -This is a repository used to host various programs in c language as a part of our Data Structure lab.The programs that have been completed so far are -1. Linked list implementation in C -2. Stack implementation using array -3. Stack implementation using linked list -4. Queue implementation using array -5. Queue implementation using linked list -6. Creation of a polynomial using linked list -7. Addition of a polynomial using linked list -8. Implementation of doubly ended queue in C -9. Conversion and evaluation of infix expressions to postfix expressions using stack. +This is a repository used to host various programs in C language as a part of our Data Structure lab.The programs that have been completed so far are + +1. Different Searching methods +2. Different Sorting methods +3. Linked list implementation in C +4. Stack implementation using array +5. Stack implementation using linked list +6. Queue implementation using array +7. Queue implementation using linked list +8. Creation of a polynomial using linked list +9. Addition of a polynomial using linked list +10. Implementation of doubly ended queue in C +11. Conversion and evaluation of infix expressions to postfix expressions using stack.