本文整理汇总了C++中preorder函数的典型用法代码示例。如果您正苦于以下问题:C++ preorder函数的具体用法?C++ preorder怎么用?C++ preorder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了preorder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main() {
int n;
scanf("%d", &n);
int tree[n + 1][2], idx = 0;
while (++idx <= n) {
scanf("%d %d", &tree[idx][0], &tree[idx][1]);
}
preorder(tree, 1);
printf("\n");
inorder(tree, 1);
printf("\n");
postorder(tree, 1);
return 0;
}
开发者ID:mijiacang,项目名称:OnlineJudge,代码行数:14,代码来源:3143.cpp
示例2: inorder
void bintree<T>::display()
{
if(root==NULL)
cout<<"Tree Is Not Created";
else
{
cout<<"\n The Inorder Traversal of Tree is : ";
inorder(root);
cout<<"\n The Preoder Traversal of Tree is : ";
preorder(root);
cout<<"\n The Preoder Traversal of Tree is : ";
postorder(root);
}
}
开发者ID:laddu74,项目名称:Programming-Language,代码行数:14,代码来源:bst_nonrec.cpp
示例3: main
void main() {
node root = NULL;
root = insert(root, 10);
root = insert(root, 20);
root = insert(root, 30);
root = insert(root, 40);
root = insert(root, 50);
root = insert(root, 25);
printf("\nThe preorder traversal is: ");
preorder(root);
printf("\n");
}
开发者ID:vshan,项目名称:DSA-Stuff,代码行数:14,代码来源:avl_tree.c
示例4: main
int main(int argc, char *argv[]) {
struct Node *root = new Node(1);
root->left = new Node(2);
root->right = new Node(3);
root->left->left = new Node(4);
root->left->right = new Node(5);
root->right->left = new Node(6);
root->right->right = new Node(7);
std::cout << "Preorder Traversal(iterative): ";
preorder(root);
std::cout << "\n";
return 0;
}
开发者ID:elinus,项目名称:CODE,代码行数:14,代码来源:PreOrder_iter.cpp
示例5: main
int main(void)
{
Tree *root = (Tree *)malloc(sizeof(Tree));
root->left = root->right = root->parent = NULL;
root->val = INT_MIN;
int i = 0;
int minlen = INT_MAX;
int templen = 0;
for (i = 1; i <= 1024; i++) {
insert(root, i);
}
preorder(root->left);
printf("\n");
for (i = 1; i <= 1024; i++) {
find(root, i);
}
preorder(root->left);
printf("\n");
return 0;
}
开发者ID:leicj,项目名称:books,代码行数:23,代码来源:4.26.c
示例6: main
void main()
{ int n,digit,g,o;
node *insert(node *,int );
void preorder(node *P);
void inorder(node *P);
void postorder(node *P);
void deltree(void);
do
{
printf("\tWhat do you want to do? \n");
printf("\t\t 1) insert the element:\n");
printf("\t\t 2) preorder traversal:\n");
printf("\t\t 3) inorder traversal:\n");
printf("\t\t 4) postorder traversal:\n");
printf("\t\t 5) delete \n");
scanf("%d",&n);
switch(n)
{
case 1: printf("\tEnter the digit:\n");
scanf("%d",&digit);
while(digit!=0)
{
P=insert(P,digit);
scanf("%d",&digit);
}
break;
case 2: printf("\tThe preorder traversal is as follows:\n");
preorder(P);
getch();
break;
case 3: printf("\t The inorder traversal is as follows:\n");
inorder(P);
getch();
break;
case 4: printf("\t The postorder traversal is as follows:\n");
postorder(P);
getch();
break;
case 5: printf("\t delete\n");
deltree();
break;
}
printf("\t DO you want to continue:\n");
printf("\t 1)YES\n");
printf("\t 2)NO\n");
scanf("%d",&g);
clrscr();
}while(g==1);
}
开发者ID:makwanasameer,项目名称:Data-Structure-and-Algorithms,代码行数:50,代码来源:BinarySearchTree_RECURSSION.C
示例7: main
int main()
{
int pre[] = {5,3,6,2,7,1,4,8,9};
int in[] = {1,2,3,4,5,6,7,8,9};
struct BT *root = makeTree(in, pre, 0, sizeof(pre)/sizeof(pre[0]));
printf("\t====inordeer====\n");
inorder(root);
printf("\t====preordeer====\n");
preorder(root);
return 0;
}
开发者ID:RAJU009F,项目名称:my-work,代码行数:14,代码来源:preinT.c
示例8: main
int main()
{
struct node * root = newnode(1);
root->left=newnode(2);
root->right=newnode(3);
root->left->left=newnode(4);
root->left->right=newnode(5);
printf("preorder\n");
preorder(root);
printf("INorder\n");
inorder(root);
printf("postorder\n");
postorder(root);
return 0;
}
开发者ID:Farheen2302,项目名称:Algorithms,代码行数:15,代码来源:Tree_traversal.c
示例9: preorder
pair<TreeNode*, TreeNode*> preorder(TreeNode *root)
{
if(root == NULL)
return make_pair(root, root);
pair<TreeNode*, TreeNode*> left = preorder(root->left);
pair<TreeNode*, TreeNode*> right = preorder(root->right);
root->left = NULL;
TreeNode *tail = root;
if(left.first)
{
tail->right = left.first;
tail = left.second;
}
if(right.first)
{
tail->right = right.first;
tail = right.second;
}
return make_pair(root, tail);
}
开发者ID:starmsg,项目名称:problem_set,代码行数:24,代码来源:Flatten+Binary+Tree+to+Linked+List.cpp
示例10: main
int main()
{
int row = 3;//no. of input lines
//1st element in each row is node Value, 2nd - no of child, ,>=3rd....=>value of child
int data[3][5]={{1,3,2,3,4},{2,2,5,6,0},{3,3,8,9,10}};
int i;
struct tree* root=NULL;
for(i=0;i<row;i++)
{
// preorder(root);
root = createnary(root,data[i]);
}
preorder(root);
}
开发者ID:vishnujayvel,项目名称:practicecodes,代码行数:15,代码来源:nnarytree.cpp
示例11: main
int main(int argc, char *argv[]){
element_type array[20];
element_type array1[20];
int i;
BTREE T1 = init_tree();
BTREE T2 = init_tree();
BTREE T3 = NULL;
for(i=0; i<20; i++){
array[i] = random(200);
array1[i] = i;
printf("%d ", array[i]);
}
printf("\n");
T1 = creat_tree(array, sizeof(array)/sizeof(array[0]), T1);
T2 = creat_tree(array, 1, T2);
preorder(T1);
printf("\n");
preorder(T2);
printf("\n");
if(contain_tree(T1, T2))
printf("T1 contains T2\n");
else
printf("T1 doesn't contain T2\n");
free_tree(T1);
free_tree(T2);
return 0;
}
开发者ID:Trietptm-on-Coding-Algorithms,项目名称:data-structure,代码行数:36,代码来源:subtree.c
示例12: main
main()
{
int choice,num;
root=NULL;
while(1)
{
printf("\n");
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Inorder Traversal\n");
printf("4.Preorder Traversal\n");
printf("5.Postorder Traversal\n");
printf("6.Display\n");
printf("7.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the number to be inserted : ");
scanf("%d",&num);
insert(num);
break;
case 2:
printf("Enter the number to be deleted : ");
scanf("%d",&num);
del(num);
break;
case 3:
inorder(root);
break;
case 4:
preorder(root);
break;
case 5:
postorder(root);
break;
case 6:
display(root,1);
break;
case 7:
exit();
default:
printf("Wrong choice\n");
}/*End of switch */
}/*End of while */
}/*End of main()*/
开发者ID:b-rajarshi,项目名称:code_ol_judges,代码行数:48,代码来源:BST.C
示例13: main
int main()
{
int n,x;
struct node *location,*parent;
do
{
printf("1.insertion\n2.deletion\n3.search\n4.inorder traversal\n5.preorder traversal\n6.postorder\n7.exit\n");
printf("\nenter ur choice\n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nenter element to be inserted\n");
scanf("%d",&x);
insert(x);
break;
case 2:
printf("\nenter element to be deleted\n");
scanf("%d",&x);
del(x);
break;
case 3:
printf("\nenter element to be searched\n");
scanf("%d",&x);
find(x,&parent,&location);
if(location!=NULL)
printf("\nsearch successfull\n");
else
printf("\nitem not found\n");
break;
case 4:
inorder(root);
break;
case 5:
preorder(root);
break;
case 6:
postorder(root);
break;
case 7:
return 0;
break;
default :
printf("\ndefault entry\n");
}
}
while(n!=7);
}
开发者ID:jithesh92,项目名称:Btech-Labs,代码行数:48,代码来源:bst.c
示例14: main
int main(void)
{
struct node* root = NULL;
//struct node* root2 = NULL;
struct node *find = NULL;
char str[1024];
root = insert(root, 10);
root = insert(root, 15);
root = insert(root, 9);
root = insert(root, 8);
root = insert(root, 13);
root = insert(root, 7);
root = insert(root, 5);
root = insert(root, 18);
root = insert(root, 22);
root = insert(root, 3);
root = insert(root, 4);
root = insert(root, 2);
root = insert(root, 1);
print_ascii_tree(root);
find = search(root, 18);
print_ascii_tree(root);
find = search(root, 22);
printf("\n\n\nDATA found is %d\n", find->data);
find = min_node(root);
printf("Min in this tree is %d\n", find->data);
find = max_node(root);
printf("Mx in this tree is %d\n", find->data);
print_ascii_tree(root);
preorder(root);
printf("\n");
inorder(root);
printf("\n");
postorder(root);
printf("\n");
printf("DEPTH is %d\n", depth(root));
tree_to_string(root, str);
printf("The STR generated is %s\n", str);
//string_to_tree(&root2, str);
//print_ascii_tree(root2);
printf("COUNT is %d\n",nodes(root));
bool res = hassum(root, 45);
printf("Bool val is %d\n", (int)res);
levelorder(root);
return 0;
}
开发者ID:abhimanyu12,项目名称:binary_trees,代码行数:48,代码来源:bin_tree.c
示例15: main
int main()
{
int n;
scanf("%d",&n);
int i;
struct node* root=NULL;
for(i=0;i<n;i++)
{
int a;
scanf("%d",&a);
insert(&root,a,NULL);
}
inorder(root);
printf("\n");
preorder(root);
printf("\n");
postorder(root);
printf("\n");
int search;
scanf("%d",&search);
int start=0;
int end=k-1;
while(start<=end)
{
if(arr[start]+arr[end]==search)
{
printf("%d %d",arr[start],arr[end]);
break;
}
else if(arr[start]+arr[end]>search)
{
end--;
}
else
{
start++;
}
}
/* searchi(root,search);
//printf("%d",root->right->left->data);
inorder(root);
printf("\n");
preorder(root);
printf("\n");
postorder(root);
printf("\n");*/
return 0;
}
开发者ID:Bminus,项目名称:Algorithms,代码行数:48,代码来源:5.c
示例16: main
int main(int argc, char *argv[])
{
int array[] = {2, 3, 4, 5, 6, 8, 10, 12, 14, 15, 16, 18, 20};
int lb = 0;
int ub = sizeof(array)/sizeof(int) - 1;
tnode *root = tnode_construct_bst(array, lb, ub);
preorder(root);
//Question
printf("\n");
postorder(root);
// Question
printf("\n");
tnode_destroy_bst(root);
// Question
return EXIT_SUCCESS;
}
开发者ID:jyshi,项目名称:ece264,代码行数:16,代码来源:exam2.c
示例17: show
show(NodeT *root,int level)
{
while ('\n' != getc(stdin));
printf( "\nPreorder listing\n" );
preorder( root, 0 );
printf( "Press Enter to continue." );
while ('\n' != getc(stdin));
printf( "\nInorder listing\n" );
inorder( root, 0 );
printf( "Press Enter to continue." );
while ('\n' != getc(stdin));
printf( "\nPostorder listing\n" );
postorder( root, 0 );
printf( "Press Enter to continue." );
while ('\n' != getc(stdin));
}
开发者ID:kakas4,项目名称:C_programming,代码行数:16,代码来源:main.c
示例18: main
int main() {
nptr root = NULL;
Insert(&root, 10);
Insert(&root, 11);
Insert(&root, 7);
Delete(root, 11);
Insert(&root, 15);
Insert(&root, 12);
preorder(root); printf("\n\n");
//inorder(root); printf("\n\n");
//postorder(root); printf("\n\n");
return 0;
}
开发者ID:sanghoon66,项目名称:DataStructure,代码行数:16,代码来源:tree.cpp
示例19: main
void main(void)
{
int ch;
char y;
int data;
struct node *temp;
while(1)
{
printf("\n\n\n1: Insert\t2: Inorder Traversal\t3: Preorder Traversal\t4: Postorder Traversal\t5: Exit\nEnter you choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter data value: ");
scanf("%d",&data);
temp=new_node(data);
if(root==NULL)
{
root=temp;
}
else
insert(root,temp);
break;
case 2:
inorder(root);
break;
case 3:
preorder(root);
break;
case 4:
postorder(root);
break;
case 5:
exit(0);
default: printf("\nInvalid Choice !");
}
}
}
开发者ID:gowtham-munukutla,项目名称:All-My-Codes,代码行数:46,代码来源:completebinarytree.c
示例20: main
int main()
{
Node* root;
int arr[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
maketree(arr, 0, sizeof(arr)/sizeof(int)-1, &root);
inorder(root);
printf("height is %d\n", height(root));
preorder(root);
printf("Balance: %d\n", isBalanced(root));
return 0;
}
开发者ID:seanxiao2net,项目名称:InterviewLearning,代码行数:17,代码来源:q43.c
注:本文中的preorder函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论