本文整理匯總了C++中inorder函數的典型用法代碼示例。如果您正苦於以下問題:C++ inorder函數的具體用法?C++ inorder怎麽用?C++ inorder使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了inorder函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: main
/******************************************************************************
*Function : main
*Input parameters: no parameters
*RETURNS : 0 on success
******************************************************************************/
int main(void)
{
bool ht_inc;
int info,choice;
NODEPTR root;
root = NULL;
while(1)
{
printf("1.Insert\n2.Display\n3.Quit\nEnter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("Enter the value to be inserted : ");
scanf("%d", &info);
if( search(root,info) == NULL )
root=insert(info, root, &ht_inc);
else
printf("Duplicate value ignored\n");
break;
case 2:if(root==NULL)
{
printf("Tree is empty\n");
continue;
}
printf("Tree is :\n");
printf("Inorder Traversal is: ");
inorder(root);
printf("\n \n");
break;
case 3:exit(1);
default:printf("Wrong choice\n");
}
}
return 0;
}
示例2: main
int main() {
int i;
int n;
char in[1024];
char out[1024];
NodePointer root;
printf("Input data by Reverse Polish Notation: ");
scanf("%s", in);
root = tree_by_revpol(in);
n = 0;
preorder(root, out, &n);
printf("preorder: ");
for ( i = 0; i < n; ++ i ) {
printf("%c ", out[i]);
}
printf("\n");
n = 0;
inorder(root, out, &n);
printf("inorder: ");
for ( i = 0; i < n; ++ i ) {
printf("%c ", out[i]);
}
printf("\n");
n = 0;
postorder(root, out, &n);
printf("postorder: ");
for ( i = 0; i < n; ++ i ) {
printf("%c ", out[i]);
}
printf("\n");
return 0;
}
示例3: main
int main()
{
int Q;
scanf("%d",&Q);
while (Q--)
{
char op[10];
scanf("%s",op);
if (op[0]=='i')
{
int x;
scanf("%d",&x);
insert(root,x,0);
}
else if (op[0]=='f')
{
int x;
scanf("%d",&x);
printf("%s\n",find(root,x)?"yes":"no");
}
else if (op[0]=='d')
{
int x;
scanf("%d",&x);
del(root,x);
}
else
{
inorder(root);
printf("\n");
preorder(root);
printf("\n");
}
}
return(0);
}
示例4: main
int main()
{
FILE * fin = fopen("input.txt", "r");
FILE * fout = fopen("output.txt", "w");
tree root;
tree node;
tree rear, front;
int n, tmp;
int i;
fscanf(fin, "%d", &n);
root = (tree)malloc(sizeof(*root));
root->next = NULL;
root->parent = NULL;
root->rc = NULL;
root->lc = NULL;
node = root;
for ( i = 0 ; i < n ; i ++ )
{
fscanf(fin, "%d", &tmp);
insert(&root, &node, tmp);
}
front = root->next;
rear = root->next;
while(1)
{
if(rear->next != NULL)
{
rear = rear->next;
if(rear->val != 0 )
{
rear->parent = front;
front->lc = rear;
}
}
if(rear->next != NULL)
{
rear = rear->next;
if(rear->val != 0)
{
rear->parent = front;
front->rc = rear;
}
}
front = front->next;
if(front == NULL)
{
break;
}
}
inorder((root->next), fout);
rip(&root);
//free(root);
fclose(fin);
fclose(fout);
return 0;
}
示例5: inorder
void BTree<T>::inorder() {
inorder(manager.get_root());
cout << endl;
}
示例6: inorder
void inorder(TreeNode *p) {
if (!p) return;
inorder(p->left);
ptr.push_back(p);
inorder(p->right);
}
示例7: inorderTraversal
vector<int> inorderTraversal(TreeNode *root)
{
inorder(root);
return nodes;
}
示例8: inorder
void BSTree::inOrderPrint() {
inorder(root);
}//end inOrderPrint.
示例9: main
void main() {
int choice;
char ans = 'N';
int key;
Nodo *nuevo_nodo, *raiz, *tmp;
raiz = NULL;
system("clear");
printf("\nPrograma para árbol de búsqueda binaria:");
do {
printf("\n1.Insertar");
printf("\n2.Buscar");
printf("\n3.Listar árbol");
printf("\n4.Dibujar arbol");
printf("\n5.Exit");
printf("\nIndicar operación : ");
scanf("%d", &choice);
switch (choice) {
case 1:
do {
nuevo_nodo = crear_nodo(1);
printf("\nIngresar elemento : ");
scanf("%d", &nuevo_nodo->clave);
insertar(&raiz, &nuevo_nodo);
printf("\nQuiere ingresar mas elementos?(y/n) : ");
scanf(" %c", &ans);
} while (ans == 'y');
break;
case 2:
printf("\nIngresar clave a ser buscada : ");
scanf("%d", &key);
tmp = buscar(&raiz, key);
if(tmp == NULL)
printf("\nNo existe la clave en el árbol!!!");
break;
case 3:
if (raiz == NULL) {
printf("Arbol no está creado.");
} else {
printf("\nMostrar Inorder : ");
inorder(&raiz);
printf("\nMostrar Preorder : ");
preorder(&raiz);
printf("\nMostrar Postorder : ");
postorder(&raiz);
}
break;
case 4:
dibujar_arbol(raiz);
break;
}
} while (choice != 5);
}
示例10: main
int main()
{
int i,num,ch;
count=0;
for(i=0;i<20;i++)
ar[i]=0;
do {
printf("###Array implementation of a binary TREE###\n1.insert an element into the TREE\n2.delete a node from the TREE\n3.dispaly the nodes in the TREE\n4.search the nodes in the TREE\n5.exit\nENTER A ValID CHOICE TO PROCEED");
scanf("%d",&ch);
switch (ch) {
case 1:
{
printf("enter the element to be inserted:\n");
scanf("%d",&num);
ar[count]=num;
count++;
}
break;
case 2:
{
printf("enter the element to be deleted:\n");
scanf("%d",&num);
for(i=0;i<count;i++)
{
if (ar[i]==num)
{
count--;
ar[i]=ar[count];
ar[count]=0;
/* code */
}
}
/* code */
}
break;
case 4:
{
printf("enter the element to searched:\n");
scanf("%d",&num);
for(i=0;i<count;i++)
{
if(ar[i]==num)
{
printf("the element is hit at index %d",(count-1));
break;
}
}
if(i==count)
{
printf("the element is not found");
}
}
break;
case 3:
{
inorder(0);
printf("\n");
}
break;
case 5:
{
printf("\n\nAdios!\n\n");
exit(0);
}
break;
}
/* code */
} while(ch!=5);
return 0;
}
示例11: Solution
//@param root: The root of binary tree.
Solution(TreeNode *root) {
// write your code here
inorder(root);
}
示例12: inorder
void inorder(TreeNode * n) {
if (! n) return;
inorder(n->left);
v.push_back(n);
inorder(n->right);
}
示例13: inorderSuccessor
TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {
if (!p) return NULL;
inorder(root, p);
return suc;
}
示例14: inorder
void inorder() { inorder(root); }
示例15: main
int main(void)
{
struct Node *root = NULL;
root_ptr = NULL;
long int loop;
long int value;
int ch;long int x;
scanf("%ld",&loop );
x = loop;
while(loop --)
{
// ch = 1;
scanf("%d %ld",&ch, &value );
// scanf("%ld", &value);
switch (ch) {
case 0 :
// (search(root, value)) ? printf("%s\n", "VALUE FOUND") : printf("%s\n", "VALUE NOT FOUND");
break;
case 1:
rb_tr_insert( value);
root = root_ptr;
inorder(root);
break;
case 2:
root = root_ptr;
if(!root)
{
printf("%s\n", "ROOT IS NULL");
break;
}
rb_tr_delete(value);
root = root_ptr;
inorder(root);
break;
case 3:
root = root_ptr;
// printf("rank of element %ld : %ld\n",value, rank(root, value));
break;
case 4:
// root = root_ptr;
// if(! root)
// break;
// if(value > 1+root->lcount+root->rcount)
// {
// printf("%s\n","EXCEEDS NUMBER OF ELEMENTS PRESENT IN TREE" );
// break;
// }
// printf("no at rank %ld : %ld\n",value, find_rank(root, value));
break;
default:
break;
}
}
printf("red nodes : %d\n", red_count(root_ptr));
printf("root color : %s\n",(root_ptr->col)? "RED" : "BLACK" );
printf("black nodes : %d\n", black_count(root_ptr));
printf("lcount : %d, rcount = %d\n",root_ptr->lcount, root_ptr->rcount );
// check_double_red(root_ptr);
// black_path(root_ptr,0);
// inorder(root_ptr);
return EXIT_SUCCESS;
}