Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "list.h"
- #include <stdio.h>
- // Using the same node structure I defined in list.h
- struct my_node {
- struct my_node *next;
- int value;
- };
- int main() {
- LIST(my_list);
- // Creating Nodes on the stack
- struct my_node item1, item2, item3;
- // Adding Nodes To "my_list"
- list_add(my_list, &item1);
- list_add(my_list, &item2);
- list_push(my_list, &item3);
- // Pairing Up Node Memory Addresses with integer values
- list_item_set_value(&item1, 42);
- list_item_set_value(&item2, 100);
- list_item_set_value(&item3, 69);
- // Using list_remove()
- list_remove(my_list, &item2);
- // Using list_tail()
- printf("list_tail()\n");
- struct my_node *tail_node = (struct my_node *)list_tail(my_list);
- if (tail_node != NULL) {
- printf("Tail Node: %d\n", tail_node->value);
- } else {
- printf("Tail Node: List was empty\n");
- }
- // Using list_length()
- printf("List Length: %d\n", list_length(my_list));
- // Using list_insert()
- struct my_node new_node;
- list_insert(my_list, &item3, &new_node);
- list_item_set_value(&new_node, 5);
- // Using list_length() the second time
- printf("List Length: %d\n", list_length(my_list));
- // Using list_contains()
- printf("Contains new_node? : %d\n", list_contains(my_list, &new_node));
- // Using list_chop()
- printf("list_chop()\n");
- for (int x = 0; x < 3; x++) {
- struct my_node *chopped_node = (struct my_node *)list_chop(my_list);
- if (chopped_node != NULL) {
- printf("Chopped Node: %d\n", chopped_node->value);
- } else {
- printf("Chopped Node: List was empty\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement