mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-15 03:10:07 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -2,17 +2,14 @@
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
struct node
|
||||
{
|
||||
struct node {
|
||||
int val;
|
||||
node *left;
|
||||
node *right;
|
||||
};
|
||||
|
||||
void CreateTree(node *curr, node *n, int x, char pos)
|
||||
{
|
||||
if (n != NULL)
|
||||
{
|
||||
void CreateTree(node *curr, node *n, int x, char pos) {
|
||||
if (n != NULL) {
|
||||
char ch;
|
||||
cout << "\nLeft or Right of " << n->val << " : ";
|
||||
cin >> ch;
|
||||
@@ -20,32 +17,25 @@ void CreateTree(node *curr, node *n, int x, char pos)
|
||||
CreateTree(n, n->left, x, ch);
|
||||
else if (ch == 'r')
|
||||
CreateTree(n, n->right, x, ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
node *t = new node;
|
||||
t->val = x;
|
||||
t->left = NULL;
|
||||
t->right = NULL;
|
||||
if (pos == 'l')
|
||||
{
|
||||
if (pos == 'l') {
|
||||
curr->left = t;
|
||||
}
|
||||
else if (pos == 'r')
|
||||
{
|
||||
} else if (pos == 'r') {
|
||||
curr->right = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BFT(node *n)
|
||||
{
|
||||
void BFT(node *n) {
|
||||
list<node *> queue;
|
||||
|
||||
queue.push_back(n);
|
||||
|
||||
while (!queue.empty())
|
||||
{
|
||||
while (!queue.empty()) {
|
||||
n = queue.front();
|
||||
cout << n->val << " ";
|
||||
queue.pop_front();
|
||||
@@ -57,38 +47,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() {
|
||||
int value;
|
||||
int ch;
|
||||
node *root = new node;
|
||||
@@ -97,8 +80,7 @@ int main()
|
||||
root->val = value;
|
||||
root->left = NULL;
|
||||
root->right = NULL;
|
||||
do
|
||||
{
|
||||
do {
|
||||
cout << "\n1. Insert";
|
||||
cout << "\n2. Breadth First";
|
||||
cout << "\n3. Preorder Depth First";
|
||||
@@ -107,8 +89,7 @@ int main()
|
||||
|
||||
cout << "\nEnter Your Choice : ";
|
||||
cin >> ch;
|
||||
switch (ch)
|
||||
{
|
||||
switch (ch) {
|
||||
case 1:
|
||||
int x;
|
||||
char pos;
|
||||
|
||||
Reference in New Issue
Block a user