/* CMPSC 311, Linked List, demo version 1b
* data structures
* function prototypes
* functions
* test program
*/
// data structures
struct node {
};
struct list {
};
// function prototypes
struct node *node_create(char *str);
struct list *list_create(char *str);
void list_insert(struct list *list, struct node *node);
void list_print(struct list *list);
// functions
// test program
// statically-allocated
list header (global)
struct list demo1 =
***;
int main(int argc, char *argv[])
{
// automatically-allocated
list header (local)
struct list
demo2 = ***;
for (int i = 0; i < argc; i++)
{
list_insert(&demo2,
node_create(argv[i]));
}
list_print(&demo2);
// dynamically-allocated
list header (local pointer)
struct list
*demo3 = list_create("demo3");
for (int i = 0; i < argc; i++)
{
list_insert(demo3, node_create(argv[i]));
}
list_print(demo3);
return 0;
}
// Draw a map of the memory, and
indicate where the lists and nodes are.
//
What’s wrong here? [discussion]