int main() { int n; tree *root = NULL; while (1) { scanf("%d", &n); if (n == -1) break; root = insert_BST_iterative(root, n); } print_awesome(root); printf("\n\n"); print_inorder(root); printf("\n\n"); //tree *start = tree_to_sll(root); //print_sll(start); tree *start = tree_to_dll(root); print_dll(start); //cleanup(&root); return 0; }
// Driver Program int main() { int array[]= {6, 9, 11, 0, 18, 22, 7, 4, 1}; int len = sizeof array/sizeof array[0]; dlistNode *d = array_to_dll(array, len); print_dll(d); return 0; }
/* * Story 8: rprint_dll */ void test8(void) { dlist dl = NULL; printf("Testing story 8: rprint_dll\n"); print_dll("Starting with empty list: ", dl); fflush(stdout); rprint_dll(dl); dl = add_dll(dl, 3); print_dll("Added 1, now: ", dl); rprint_dll(dl); dl = add_dll(dl, 2); print_dll("Added 2, now: ", dl); rprint_dll(dl); print_dll("Added 1, now: ", dl); dl = add_dll(dl, 1); rprint_dll(dl); dl = init_dll(dl); print_dll("Initialized to: ", dl); fflush(stdout); rprint_dll(dl); dl = add_dll(dl, 0); print_dll("Added 0, now: ", dl); fflush(stdout); rprint_dll(dl); }
int main(int argc, char** argv) { random_bst(); struct node* bst_root = generate_bst(20); printf("Pre-order\n"); pre_order_bst(bst_root); printf("\n"); printf("level-order\n"); level_order_bst(bst_root); printf("\n"); printf("Is a bst? %d\n", is_bst(bst_root)); in_order_bst(bst_root); printf("\n"); struct dll list; bst2dll(bst_root, &list); print_dll(list); destruct_dll(list); return 0; }
/* * Story 7: add_dll */ void test7(void) { dlist dl = NULL; printf("Testing story 7: add_dll\n"); print_dll("Starting with empty list: ", dl); dl = add_dll(dl, 3); print_dll("Added 3: ", dl); fflush(stdout); dl = add_dll(dl, 2); print_dll("Added 2: ", dl); fflush(stdout); dl = add_dll(dl, 1); print_dll("Added 1: ", dl); fflush(stdout); dl = init_dll(dl); print_dll("Initialized to: ", dl); dl = add_dll(dl, 0); print_dll("Added 0: ", dl); fflush(stdout); }
/* * Story 9: delete_dll */ void test9(void) { dlist dl = NULL; printf("Testing story 9: delete_dll\n"); print_dll("Starting with empty list: ", dl); dl = delete_dll(dl, 5); print_dll("Failed to delete position 5: ", dl); fflush(stdout); dl = init_dll(dl); print_dll("Initialized to: ", dl); dl = delete_dll(dl, 0); print_dll("De1eted position 0: ", dl); fflush(stdout); dl = delete_dll(dl, 2); print_dll("Failed to delete position 2: ", dl); fflush(stdout); dl = delete_dll(dl, 1); print_dll("De1eted position 1: ", dl); fflush(stdout); }