AVL Insertion(浙大pta)
生活随笔
收集整理的這篇文章主要介紹了
AVL Insertion(浙大pta)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
6 -1 AVL Insertion(浙大pta)##
6 -1 AVL Insertion
You are supposed to implement the Insert function, which inserts an integer Key into an AVL tree T. The resulting tree must be returned.
Format of function:
where AVLTree is defined as the following:
typedef struct AVLNode *PtrToAVLNode; struct AVLNode{int Key;PtrToAVLNode Left;PtrToAVLNode Right;int Height; }; typedef PtrToAVLNode AVLTree;Sample program of judge:
#include <stdio.h> #include <stdlib.h>typedef struct AVLNode *PtrToAVLNode; struct AVLNode{int Key;PtrToAVLNode Left;PtrToAVLNode Right;int Height; }; typedef PtrToAVLNode AVLTree;AVLTree Insert ( AVLTree T, int Key ); void PostOrderPrint( AVLTree T ); /* details omitted */ void InOrderPrint( AVLTree T ); /* details omitted */int main() {int N, Key, i;AVLTree T = NULL;scanf("%d", &N);for ( i=0; i<N; i++ ){scanf("%d", &Key);T = Insert( T, Key );}PostOrderPrint( T );InOrderPrint( T );return 0; } /* Your function will be put here */Sample Input:
7
88 70 61 96 120 90 65
Sample Output:
Post-order: 61 70 65 90 120 96 88
In-order: 61 65 70 88 90 96 120
總結
以上是生活随笔為你收集整理的AVL Insertion(浙大pta)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#学习笔记二(函数高级参数)
- 下一篇: 金融大总结