Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create bst.cpp #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions c++/bst.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}
24 changes: 24 additions & 0 deletions queue.cpp
Original file line number Diff line number Diff line change
@@ -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];
}