#ifndef UTILS_HEADER
#define UTILS_HEADER
#include "utils.h"
#endif
#include "MS.h"
struct treenode* MS01Util(struct treenode* root, int flag){
if (root == NULL){
return NULL;
}
struct treenode* left = MS01Util(root->lchild, 0);
struct treenode* right = MS01Util(root->rchild, 1);
if (left != NULL){
left->rchild = root;
root->lchild = left;
}
if (right != NULL){
right->lchild = root;
root->rchild = right;
}
struct treenode* result = root;
if (flag == 0){
while (root != NULL){
result = root;
root = root->rchild;
}
}
else{
while (root != NULL){
result = root;
root = root->lchild;
}
}
return result;
}
void MS01(){
double array[] = { 2, 3, 1, 5, 4, 2, 6, 3, 5, 1, 2, 4, 6, 3, 2, 1, 4 };
struct treenode* root = gene2OrTree(array, 17);
cout << endl;
root = MS01Util(root, 1);
while (root != NULL){
cout << root->value << " ";
root = root->rchild;
}
cout << endl;
return;