From 472a0e094b1800b6e597cff8c0196d404b16edaa Mon Sep 17 00:00:00 2001 From: nagln Date: Thu, 1 Oct 2020 09:59:31 +0530 Subject: [PATCH 1/2] Create bst.cpp --- c++/bst.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 c++/bst.cpp diff --git a/c++/bst.cpp b/c++/bst.cpp new file mode 100644 index 0000000..af45c8b --- /dev/null +++ b/c++/bst.cpp @@ -0,0 +1,43 @@ +//main function can be constructed as your wish +void perorder(struct node*root) + { + if(root) + { + printf("%d ",root->data); //Printf root->data + preorder(root->left); //Go to left subtree + preorder(root->right); //Go to right subtree + } + } +void postorder(struct node*root) + { + if(root) + { + postorder(root->left); //Go to left sub tree + postorder(root->right); //Go to right sub tree + printf("%d ",root->data); //Printf root->data + } + } +void inorder(struct node*root) + { + if(root) + { + inorder(root->left); //Go to left subtree + printf("%d ",root->data); //Printf root->data + inorder(root->right); //Go to right subtree + } + } +struct node* insert(struct node* root, int data) + { + if (root == NULL) //If the tree is empty, return a new,single node + return newNode(data); + else + { + //Otherwise, recur down the tree + if (data <= root->data) + root->left = insert(root->left, data); + else + root->right = insert(root->right, data); + //return the (unchanged) root pointer + return root; + } + } From 81c58fb0cd171a86d593ddfcb2ca16b4a89ac7a1 Mon Sep 17 00:00:00 2001 From: nagln Date: Thu, 1 Oct 2020 10:38:53 +0530 Subject: [PATCH 2/2] Create queue.cpp --- queue.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 queue.cpp diff --git a/queue.cpp b/queue.cpp new file mode 100644 index 0000000..e4e4539 --- /dev/null +++ b/queue.cpp @@ -0,0 +1,24 @@ +//use main function as you wish + +void enqueue(char queue[], char element, int& rear, int arraySize) { + if(rear == arraySize) // Queue is full + printf("OverFlow\n"); + else { + queue[rear] = element; // Add the element to the back + rear++; + } +} + + +void dequeue(char queue[], int& front, int rear) { + if(front == rear) // Queue is empty + printf("UnderFlow\n"); + else { + queue[front] = 0; // Delete the front element + front++; + } +} + +char Front(char queue[], int front) { + return queue[front]; +}