-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
38 lines (31 loc) · 1.17 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (C) 2013 Randy Gaul
// All rights reserved.
// This code is for illustration purposes to be studied in
// conjunction with online slideshows. Do not use any of
// this code in your project. You must write every character
// in your own projects from scratch. Trust me, you don't
// actually WANT to use any of this code in your project.
#include <stdio.h> // printf
#include "List.h"
int main( void )
{
List *list = CreateList( );
node *n;
int x = 17;
int y = 18;
int z = 19;
InsertFront( list, &x, sizeof( int ) );
InsertFront( list, &y, sizeof( int ) );
InsertFront( list, &z, sizeof( int ) );
// Loop through list. It's important to use ListBegin and ListEnd for proper looping.
// Make note of what pointers Begin and End return.
for(n = ListBegin( list ); n != ListEnd( list ); n = n->next)
printf( "%d\n", NODE_DATA( n, int ) );
// Proper way to delete nodes from list is like so:
// note -- we are not doing n = n->next within the for loop, instead
// we use the return value of delete
for(n = ListBegin( list ); n != ListEnd( list );)
n = DeleteNode( list, n );
getchar( );
return 0;
}