Beispiel #1
0
void display_tree_inorder(struct Node *node) {
    if(node != NULL) {
        display_tree_inorder(node->left);
        printf("%d ", node->value); 
        display_tree_inorder(node->right);
    }
}
Beispiel #2
0
void display_tree_inorder(struct node *root)
{
	if(root != NIL)
	{
		display_tree_inorder(root->left);
		printf("%d\n", root->key);
		display_tree_inorder(root->right);
	}
}
Beispiel #3
0
int main(int argc, char **argv) {
    struct Node *root;
    root = NULL;

    while(1) {
        printf("\nEnter integer: ");
        int value;
        scanf("%d", &value);
        insert_node(&root, value);
        display_tree_inorder(root);
    };

    return 0;
}
Beispiel #4
0
int main()
{
	struct node *root;
	char buffer[128];
	char response;
	int value;
	
	NIL = (struct node *) malloc(sizeof(struct node));
	NIL->key = -1;
	NIL->color = BLACK;
	NIL->parent = NULL;
	NIL->left = NULL;
	NIL->right = NULL;
	
	root = NIL;
	
	do
	{
		printf("Enter a to insert, s to search, k to display the red-black tree and e to exit\n");
		fgets(buffer, 128, stdin);
		sscanf(buffer, "%c", &response);
		switch(response)
		{
			case 'a':
				printf("Enter value to insert: ");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				insert(&root, value);
				break;
			/*case 's':
				printf("Enter value to search: ");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				if(search(root, value) != NIL)
					printf("%d is present\n", value);
				else
					printf("%d is not present\n", value);
				break;
			case 'd':
				printf("Enter value to delete: ");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				delete(&root, search(root, value));
				break;
			case 'f':
				printf("Which value's successor should be displayed?\n");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				successor(root, value);
				break;
			case 'g':
				printf("Which value's predecessor should be displayed?\n");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				predecessor(root, value);
				break;
			case 'h':
				temp = minimum(root);
				if(temp != NULL)
					printf("Minimum node in the tree is %d\n", temp->key);
				else
					printf("Empty tree\n");
				break;
			case 'j':
				temp = maximum(root);
				if(temp != NULL)
					printf("Maximum node in the tree is %d\n", temp->key);
				else
					printf("Empty tree\n");
				break;*/
			case 'k':
				display_tree_inorder(root);
				break;
			case 'e':
				break;
			default:
				printf("Wrong option\n");
				break;
		}
	}
	while(response != 'e');
	return 1;
}