formatting source-code for 153fb7b8a5

This commit is contained in:
github-actions
2020-05-30 04:02:09 +00:00
parent 92fe9495ec
commit 8a2de9842b
175 changed files with 1671 additions and 3460 deletions

View File

@@ -1,15 +1,13 @@
#include <iostream>
using namespace std;
struct node
{
struct node {
int val;
node *left;
node *right;
};
struct queue
{
struct queue {
node *t[100];
int front;
int rear;
@@ -21,107 +19,71 @@ void enqueue(node *n) { q.t[q.rear++] = n; }
node *dequeue() { return (q.t[q.front++]); }
void Insert(node *n, int x)
{
if (x < n->val)
{
if (n->left == NULL)
{
void Insert(node *n, int x) {
if (x < n->val) {
if (n->left == NULL) {
node *temp = new node;
temp->val = x;
temp->left = NULL;
temp->right = NULL;
n->left = temp;
}
else
{
} else {
Insert(n->left, x);
}
}
else
{
if (n->right == NULL)
{
} else {
if (n->right == NULL) {
node *temp = new node;
temp->val = x;
temp->left = NULL;
temp->right = NULL;
n->left = temp;
}
else
{
} else {
Insert(n->right, x);
}
}
}
int findMaxInLeftST(node *n)
{
while (n->right != NULL)
{
int findMaxInLeftST(node *n) {
while (n->right != NULL) {
n = n->right;
}
return n->val;
}
void Remove(node *p, node *n, int x)
{
if (n->val == x)
{
if (n->right == NULL && n->left == NULL)
{
if (x < p->val)
{
void Remove(node *p, node *n, int x) {
if (n->val == x) {
if (n->right == NULL && n->left == NULL) {
if (x < p->val) {
p->right = NULL;
}
else
{
} else {
p->left = NULL;
}
}
else if (n->right == NULL)
{
if (x < p->val)
{
} else if (n->right == NULL) {
if (x < p->val) {
p->right = n->left;
}
else
{
} else {
p->left = n->left;
}
}
else if (n->left == NULL)
{
if (x < p->val)
{
} else if (n->left == NULL) {
if (x < p->val) {
p->right = n->right;
}
else
{
} else {
p->left = n->right;
}
}
else
{
} else {
int y = findMaxInLeftST(n->left);
n->val = y;
Remove(n, n->right, y);
}
}
else if (x < n->val)
{
} else if (x < n->val) {
Remove(n, n->left, x);
}
else
{
} else {
Remove(n, n->right, x);
}
}
void BFT(node *n)
{
if (n != NULL)
{
void BFT(node *n) {
if (n != NULL) {
cout << n->val << " ";
enqueue(n->left);
enqueue(n->right);
@@ -129,38 +91,31 @@ void BFT(node *n)
}
}
void Pre(node *n)
{
if (n != NULL)
{
void Pre(node *n) {
if (n != NULL) {
cout << n->val << " ";
Pre(n->left);
Pre(n->right);
}
}
void In(node *n)
{
if (n != NULL)
{
void In(node *n) {
if (n != NULL) {
In(n->left);
cout << n->val << " ";
In(n->right);
}
}
void Post(node *n)
{
if (n != NULL)
{
void Post(node *n) {
if (n != NULL) {
Post(n->left);
Post(n->right);
cout << n->val << " ";
}
}
int main()
{
int main() {
q.front = 0;
q.rear = 0;
int value;
@@ -171,8 +126,7 @@ int main()
root->val = value;
root->left = NULL;
root->right = NULL;
do
{
do {
cout << "\n1. Insert";
cout << "\n2. Delete";
cout << "\n3. Breadth First";
@@ -183,8 +137,7 @@ int main()
cout << "\nEnter Your Choice : ";
cin >> ch;
int x;
switch (ch)
{
switch (ch) {
case 1:
cout << "\nEnter the value to be Inserted : ";
cin >> x;