コード例 #1
0
int main(){
	node *head;
	int n;
	head=NULL;
	int i;
	for(i=11;i<=18;i++)
		head=insertInDll(head,i);
	printDLL(head);
	//head=reverseList(head);
	//printDLL(head);
	node *root=sortedToBST(head);
	printf("\nInorder traversal is:");
	inorder(root);
	printf("\n");
	return 0;
}
コード例 #2
0
// Main Function, controls program flow
int main()
{

	CNode *pHeadC;		// For the Doubly linked list
	CNode *pRoot;		// For the binary tree

	// Initializing doubly linked list
	pHeadC = (CNode*)malloc(sizeof(CNode));
	pHeadC->pNext = NULL;
	pHeadC->pPrevious = NULL;

	// Let the user know what we are doing
	printf("\n\nPlease enter a series of integers.\n");
	printf("These will first be stored in a doubly linked list,\n");
	printf("then converted into a binary tree.\n");

	pHeadC = getNumbers(pHeadC);
	
	printf("\nGreat! Before we begin, let's print the doubly linked list: \n");
	
	printDLL(pHeadC);
	
	pRoot = convDLLtoBT(pHeadC);
	
	printf("\n\nLooks good!  Now, let's convert that doubly linked list into a binary tree.\n");

	printf("\nFirst, let's print our binary tree in order:\n");
	printTree(pRoot);
	
	printf("\n\nNow, let's print our binary tree in preorder walk traversal:\n");
	printTreePreOrder(pRoot);
	
	printf("\n\nNow, let's print our binary tree in postorder walk traversal:\n");
	printTreePostOrder(pRoot);
	
	freeTreeMem(pRoot);

	printf("\n\n");
	
	return 0;
}