2016-04-18 87 views
0

我在C中實現AVL樹,我想在控制檯的三列中打印樹的所有元素。在列中打印AVL樹

我有這樣的:

void printInOrder(nodo * raiz){ 
    if(raiz!=NULL){ 
    printInOrder(raiz->esq); 
    printf("%s\n",raiz->codigo); 
    printInOrder(raiz->dir); 
    } 
} 

任何人都知道如何打印輸出分三路?

+0

善有善報,在第1列,第2列,第3列?請顯示一個示例樹(可能是7-8個節點)和預期的輸出。就目前而言,沒有一種簡單的方法來回答你的問題。 –

+0

如果你有這樣的事情: 'code' 串1 /\ 字符串2字符串3 /\ 字串4字串5 您將結束: 字串4 字符串2 字串5 串1串 我想要的是: 串4串5串3 串2串1 –

+0

請添加信息的問題,你可以將其格式化sowe有機會了解你在做什麼。 –

回答

0

這就是我正在尋找:

int printInOrder(nodo *root, int count){ 
if(root!=NULL){ 
    count=printInOrder(root->left,count); 
    count++; 
    if(count%PRINT_COLS==0 && count!=0) printf("%s \n", root->code); 
    else printf("%s \t\t", root->code); 
    if(count%(2*10*PRINT_COLS)==0 && count!=0){getch();} 
    count=printInOrder(root->right, count); 
} 
return count; 

}