Commit d8f7825d authored by Liam E. Roeth's avatar Liam E. Roeth

Add some functions to test

parent 4f7b3269
...@@ -3,19 +3,29 @@ ...@@ -3,19 +3,29 @@
#include "llist.h" #include "llist.h"
int main(){ int main(){
puts("Constructing list manually...");
NODE *two = construct(5, NULL); NODE *two = construct(5, NULL);
NODE *one = construct(1, two); NODE *one = construct(1, two);
NODE *root = construct(3, one); NODE *root = construct(3, one);
print_list(root); print_list(root);
printf("Searching for 5...\n"); puts("Adding 7 to end...");
add_to_end(root, 7);
print_list(root);
printf("Now it is %d elements long.\n", length(root));
printf("The head is at %p.\n", root);
puts("Adding 6 to the beginning and 8 at index 2...");
insert_node(root, 0, 6);
insert_node(root, 2, 8);
print_list(root);
printf("The head is still at %p.\n", root);
puts("Searching for 5...");
NODE_ERR target = search(root, 5); NODE_ERR target = search(root, 5);
printf("I found it at index %d\n", target.err); printf("I found it at index %d.\n", target.err);
printf("The number I found there was "); fputs("The number I found there was: ", stdout);
print_node(target.node); print_node(target.node);
printf("Deleting list...\n"); puts("Deleting list...");
delete_list(root); delete_list(root);
printf("Now it is garbage:\n"); puts("Now it is garbage:");
print_list(root); print_list(root);
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment