changeset 0:5db060528d2b

Initial import
author Eris Caffee <discordia@eldalin.com>
date Wed, 29 Dec 2010 02:14:35 -0600
parents
children 112164f48f30
files CMakeLists.txt include/LinkedList.h src/LinkedList.c src/main.c
diffstat 4 files changed, 718 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/CMakeLists.txt	Wed Dec 29 02:14:35 2010 -0600
     1.3 @@ -0,0 +1,179 @@
     1.4 +###############################################################################
     1.5 +#
     1.6 +# A generalized cmake file for developing cross-platform games.
     1.7 +#
     1.8 +# Copyright (C) 2010 Sarah Eris Horsley Caffee
     1.9 +#
    1.10 +# This is free software: you can redistribute it and/or modify
    1.11 +# it under the terms of the GNU General Public License as published by
    1.12 +# the Free Software Foundation, either version 3 of the License, or
    1.13 +# (at your option) any later version.
    1.14 +#
    1.15 +# This program is distributed in the hope that it will be useful,
    1.16 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 +# GNU General Public License for more details.
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License
    1.21 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 +#
    1.23 +#
    1.24 +# Instructions:
    1.25 +# This cmake file assumes that your source files are laid in out in the 
    1.26 +# following manner:
    1.27 +#
    1.28 +#   project_dir\		Top level directory of the project.
    1.29 +#     |---include\		Header files are here.
    1.30 +#     |---src\			Source files are here.
    1.31 +#     |---build\		Binaries/objects go here.  Run cmake from here.
    1.32 +#     !---cmake\
    1.33 +#     |     |---modules\        Custom cmake include files, if any, go here.
    1.34 +#     |---CMakeLists.txt	This file.
    1.35 +#
    1.36 +# You may have more directories, of course, but these are assumed.  You probably
    1.37 +# want more than one build directory.  I normally have build-linux\ 
    1.38 +# and build-windows\ directories.
    1.39 +#
    1.40 +# Set the App_Name variable, below, to the name of your application and you
    1.41 +# are ready to start.  Run ccmake, or cmake-gui from within your build
    1.42 +# directory, choose the options you need, such as enabling SDL, and you 
    1.43 +# should be good to go.
    1.44 +#
    1.45 +# You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you
    1.46 +# need to debug the actual makefile that is generated.
    1.47 +#
    1.48 +# On windows, you may need to set the SDLDIR environment variable to the location
    1.49 +# of your SDL installation before you run cmake-gui.
    1.50 +#
    1.51 +# When writing path names on Windows, such as when manually specifiying a 
    1.52 +# file or directory name, either use unix-style forward slashes '/' in the
    1.53 +# path names or use double backslashes. If you use a single backslash as the
    1.54 +# path name seperator, then cmake will interpret  it as an esacpe sequence.
    1.55 +# Thus, write "C:/source" or "C:\\source" instead of "C:\source".  It's
    1.56 +# probably best to use forward slashes in case to ever have a situation
    1.57 +# where cmake needs to do recursive processing: each level of cmake will
    1.58 +# strip out one of the slashes, so if there are two lev3els of cmake you
    1.59 +# need to write \\\, three levels requires \\\\, etc.
    1.60 +#
    1.61 +# Note that some of the cmake support scripts that find libraries for you
    1.62 +# can be controlled by environment variables.  For example, you can set the
    1.63 +# SDLDIR environment variable before running cmake in order to point to
    1.64 +# a different version of SDL than your systems default copy. This is useful
    1.65 +# for trying out cutting edge versions of libraries without installing them
    1.66 +# system wide.
    1.67 +
    1.68 +cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
    1.69 +#set (CMAKE_VERBOSE_MAKEFILE ON)
    1.70 +
    1.71 +# Name your program!
    1.72 +set (App_Name "LinkedList")
    1.73 +if (App_Name STREQUAL "") 
    1.74 +  message (FATAL_ERROR "You must set the App_Name variable!")
    1.75 +endif ()
    1.76 +
    1.77 +# Every project must have a name.
    1.78 +project (${App_Name})
    1.79 +
    1.80 +
    1.81 +################################################################################
    1.82 +# Special options
    1.83 +
    1.84 +
    1.85 +################################################################################
    1.86 +# Ensure that we are not building in our source directories.
    1.87 +
    1.88 +set (Build_Dir_OK "TRUE")
    1.89 +string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
    1.90 +if (In_Sub_Dir)
    1.91 +  string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
    1.92 +  if (NOT In_Build_Dir)
    1.93 +    set (Build_Dir_OK "FALSE")
    1.94 +  endif ()
    1.95 +endif ()
    1.96 +
    1.97 +if (NOT Build_Dir_OK)
    1.98 +  message (FATAL_ERROR "You must run cmake from a directory that is not in your source tree, or that is in a special subdirectory of the tree whose name begins with 'build'.")
    1.99 +endif ()
   1.100 +
   1.101 +
   1.102 +################################################################################
   1.103 +# Set up the basic build environment
   1.104 +# A build type defines which options are passed to the compiler, and there are
   1.105 +# several that CMake defines by default. It does not set one by default, though
   1.106 +# so we need to set the build type manually here, and we are setting it to the
   1.107 +# generally useful "Release with debug info"
   1.108 +
   1.109 +if (CMAKE_BUILD_TYPE STREQUAL "")
   1.110 +  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
   1.111 +  # differentiation between debug and release builds.               
   1.112 +  set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
   1.113 +endif ()
   1.114 +
   1.115 +
   1.116 +################################################################################
   1.117 +# When using GCC turn on lots of warnings.
   1.118 +
   1.119 +if (CMAKE_COMPILER_IS_GNUCXX)
   1.120 +  add_definitions(-pedantic -Wall)
   1.121 +endif ()
   1.122 +
   1.123 +
   1.124 +################################################################################
   1.125 +
   1.126 +option(Option_Profile_Program "Build for gprof profiling." OFF)
   1.127 +if (Option_Profile_Program)
   1.128 +  add_definitions(-pg)
   1.129 +  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
   1.130 +endif ()
   1.131 +
   1.132 +
   1.133 +################################################################################
   1.134 +# The core project files 
   1.135 +
   1.136 +set (SRCS_LinkedList
   1.137 +  src/LinkedList.c
   1.138 +  include/LinkedList.h
   1.139 +)
   1.140 +
   1.141 +include_directories (
   1.142 +  ${PROJECT_SOURCE_DIR}/include
   1.143 +)
   1.144 +
   1.145 +# Build both static and shared libraries
   1.146 +# The target properties are needed because, by default, the output name
   1.147 +# will be the name in the add_library command, and we need to have different
   1.148 +# names in the two commands for the shared and static versions, even though
   1.149 +# we want the final files to have the same names with different extensions.
   1.150 +#
   1.151 +# The prefix is needed mostly in case we build on windows, which has no prefix
   1.152 +# by default.
   1.153 +# 
   1.154 +# The clean_direct_output option makes sure that the two lib builds don't
   1.155 +# clobber each others temp files since they are being built from the same
   1.156 +# sources.
   1.157 +
   1.158 +add_library (LinkedList SHARED
   1.159 +  ${SRCS_LinkedList}
   1.160 +)
   1.161 +set_target_properties (LinkedList PROPERTIES OUTPUT_NAME "LinkedList")
   1.162 +set_target_properties (LinkedList PROPERTIES PREFIX "lib")
   1.163 +set_target_properties (LinkedList PROPERTIES CLEAN_DIRECT_OUTPUT 1)
   1.164 +
   1.165 +add_library (LinkedList-static STATIC
   1.166 +  ${SRCS_LinkedList}
   1.167 +)
   1.168 +set_target_properties (LinkedList-static PROPERTIES OUTPUT_NAME "LinkedList")
   1.169 +set_target_properties (LinkedList-static PROPERTIES PREFIX "lib")
   1.170 +set_target_properties (LinkedList-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
   1.171 +
   1.172 +# Build a test application.
   1.173 +
   1.174 +add_executable (test
   1.175 +  src/main.c
   1.176 +)
   1.177 +
   1.178 +target_link_libraries (test
   1.179 +  LinkedList
   1.180 +)
   1.181 +
   1.182 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/include/LinkedList.h	Wed Dec 29 02:14:35 2010 -0600
     2.3 @@ -0,0 +1,55 @@
     2.4 +/*******************************************************************************
     2.5 + * linked_list
     2.6 + *
     2.7 + * A simple doubly linked list class in C.
     2.8 + *
     2.9 + * Not thread safe.
    2.10 + *
    2.11 + * Since this class does not attempt to manage memory for the actual stored 
    2.12 + * objects, there is no "clear" method to delete the entire list.  Instead,
    2.13 + * the user must pop the entire list and delete the individually returned
    2.14 + * objects one at a time.
    2.15 + *
    2.16 + * A potential improvement would be to allow the registration of an object
    2.17 + * destructor at list creation which could then be used by a clear() method.
    2.18 + *
    2.19 + *
    2.20 + *
    2.21 + *
    2.22 + * OOH SHINY!
    2.23 + * http://tinobox.com/wordpress/object-oriented-c-coding/
    2.24 + *
    2.25 + * Looks liks good stuff.  Must read.
    2.26 + *
    2.27 + ******************************************************************************/
    2.28 +
    2.29 +#ifndef LINKEDLIST_H
    2.30 +#define LINKEDLIST_H
    2.31 +
    2.32 +typedef struct ll_node ll_node;
    2.33 +
    2.34 +typedef struct LinkedList LinkedList;
    2.35 +struct LinkedList
    2.36 +   {
    2.37 +   /* Public */
    2.38 +   void *       (* push)  (LinkedList * this, void * data);
    2.39 +   void *       (* pop)   (LinkedList * this);
    2.40 +   void *       (* insert)(LinkedList * this, void * data);
    2.41 +   void *	(* remove)(LinkedList * this);
    2.42 +   void *       (* insert_at_head)(LinkedList * this, void * data);
    2.43 +   int		(* size)  (LinkedList * this);
    2.44 +   void	*	(* head)  (LinkedList * this);
    2.45 +   void	*	(* tail)  (LinkedList * this);
    2.46 +   void	*	(* next)  (LinkedList * this);
    2.47 +   void	*	(* prev)  (LinkedList * this);
    2.48 +   void *	(* data)  (LinkedList * this);
    2.49 +
    2.50 +   /* Private (notionally, at least) */
    2.51 +   ll_node *	Head;
    2.52 +   ll_node *	Curr;
    2.53 +   ll_node *	Tail;
    2.54 +   int		Size;
    2.55 +   };
    2.56 +
    2.57 +#endif
    2.58 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/LinkedList.c	Wed Dec 29 02:14:35 2010 -0600
     3.3 @@ -0,0 +1,312 @@
     3.4 +/*******************************************************************************
     3.5 + * LinkedList
     3.6 + *
     3.7 + * A simple doubly linked list class in C.
     3.8 + *
     3.9 + * Not thread safe.
    3.10 + *
    3.11 + ******************************************************************************/
    3.12 +
    3.13 +#include "LinkedList.h"
    3.14 +
    3.15 +#include <stdlib.h>
    3.16 +
    3.17 +/*******************************************************************************
    3.18 + * "Private" inner class.
    3.19 + */ 
    3.20 +struct ll_node
    3.21 +   {
    3.22 +   ll_node *	next;
    3.23 +   ll_node *	prev;
    3.24 +   void *	data;
    3.25 +   };
    3.26 +
    3.27 +
    3.28 +/*******************************************************************************
    3.29 + * Insert an element at end of list.
    3.30 + * Sets curr and tail pointers to the new node.
    3.31 + * Returns data on success, NULL on error.
    3.32 + */
    3.33 +void * ll_push(LinkedList * this, void * data)
    3.34 +   {
    3.35 +   ll_node * new_node;
    3.36 +
    3.37 +   if ((!this) || (!data))
    3.38 +      return NULL;
    3.39 +
    3.40 +   if (!(new_node = calloc(1, sizeof(ll_node))))
    3.41 +      return NULL;
    3.42 +
    3.43 +   new_node->data = data;
    3.44 +
    3.45 +   if (!(this->Tail))
    3.46 +      {
    3.47 +      /* empty list */
    3.48 +      this->Head = this->Tail = this->Curr = new_node;
    3.49 +      }
    3.50 +   else
    3.51 +      {
    3.52 +      new_node->prev = this->Tail;
    3.53 +      this->Tail->next = new_node;
    3.54 +      this->Tail = this->Curr = new_node;
    3.55 +      }
    3.56 +
    3.57 +   this->Size++;
    3.58 +   return this->Curr->data;
    3.59 +   }
    3.60 +
    3.61 +
    3.62 +/*******************************************************************************
    3.63 + * Insert an element after the one pointed to by this->curr.
    3.64 + * Sets curr pointer to the new node (and tail if curr = tail when called).
    3.65 + * Returns data on success, NULL on error.
    3.66 + */
    3.67 +void * ll_insert(LinkedList * this, void * data)
    3.68 +   {
    3.69 +   ll_node * new_node;
    3.70 +
    3.71 +   if ((!this) || (!data))
    3.72 +      return NULL;
    3.73 +
    3.74 +   if (this->Curr == this->Tail)
    3.75 +      {
    3.76 +      return ll_push(this, data);
    3.77 +      }
    3.78 +
    3.79 +   if (!(new_node = calloc(1, sizeof(ll_node))))
    3.80 +      return NULL;
    3.81 +
    3.82 +   new_node->data = data;
    3.83 +   new_node->prev = this->Curr;
    3.84 +   new_node->next = this->Curr->next;
    3.85 +   this->Curr->next = new_node;
    3.86 +   new_node->next->prev = new_node;
    3.87 +   this->Curr = new_node;
    3.88 +
    3.89 +   this->Size++;
    3.90 +   return this->Curr->data;
    3.91 +   }
    3.92 +
    3.93 +
    3.94 +/*******************************************************************************
    3.95 + * Insert an element and make it the new head.
    3.96 + * Sets head and curr pointers to the new node.
    3.97 + * Returns data on success, NULL on error.
    3.98 + */
    3.99 +void * ll_insert_at_head(LinkedList * this, void * data)
   3.100 +   {
   3.101 +   ll_node * new_node;
   3.102 +
   3.103 +   if ((!this) || (!data))
   3.104 +      return NULL;
   3.105 +
   3.106 +   if (!(new_node = calloc(1, sizeof(ll_node))))
   3.107 +      return NULL;
   3.108 +
   3.109 +   new_node->data = data;
   3.110 +   new_node->prev = NULL;
   3.111 +   new_node->next = this->Head;;
   3.112 +
   3.113 +   if (this->Head)
   3.114 +      this->Head->prev = new_node;
   3.115 +   this->Head = this->Curr = new_node;
   3.116 +   
   3.117 +   this->Size++;
   3.118 +   return this->Curr->data;
   3.119 +   }
   3.120 +
   3.121 +
   3.122 +/*******************************************************************************
   3.123 + * Remove the tail element from the list.
   3.124 + * Sets curr to tail.
   3.125 + * Return data, or NULL if the list is empty.
   3.126 + */
   3.127 +void * ll_pop(LinkedList * this)
   3.128 +   {
   3.129 +   void * data;
   3.130 +   ll_node * tmp;
   3.131 +
   3.132 +   if (!this)
   3.133 +      return NULL;
   3.134 +
   3.135 +   if (!(this->Tail))
   3.136 +      return NULL;
   3.137 +
   3.138 +   tmp = this->Tail;
   3.139 +   data = this->Tail->data;
   3.140 +
   3.141 +   if (!(this->Tail->prev))
   3.142 +      {
   3.143 +      /* Only element in list */
   3.144 +      this->Head = this->Tail = this->Curr = NULL;
   3.145 +      }
   3.146 +   else
   3.147 +      {
   3.148 +      this->Tail->prev->next = NULL;
   3.149 +      this->Tail = this->Curr = this->Tail->prev;
   3.150 +      }
   3.151 +   
   3.152 +   free(tmp);
   3.153 +   this->Size--;
   3.154 +
   3.155 +   return data;
   3.156 +   }
   3.157 +
   3.158 +
   3.159 +/*******************************************************************************
   3.160 + * Delete the element pointed to by this->curr.
   3.161 + * A pointer to the stored data is returned, or NULL is no list or an empty list
   3.162 + * is specified.  It must be freed by the caller.
   3.163 + */
   3.164 +void * ll_remove(LinkedList * this)
   3.165 +   {
   3.166 +   void * data;
   3.167 +   ll_node * tmp;
   3.168 +
   3.169 +   if (!this)
   3.170 +      return NULL;
   3.171 +
   3.172 +   if (this->Curr == this->Tail)
   3.173 +      return ll_pop(this);
   3.174 +
   3.175 +   tmp = this->Curr;
   3.176 +   data = this->Curr->data;
   3.177 +
   3.178 +   if (this->Curr == this->Head)
   3.179 +      {
   3.180 +      this->Curr->next->prev = NULL;
   3.181 +      this->Head = this->Curr = this->Head->next;
   3.182 +      }
   3.183 +   else
   3.184 +      {
   3.185 +      this->Curr->prev->next = this->Curr->next;
   3.186 +      this->Curr->next->prev = this->Curr->prev;
   3.187 +      }
   3.188 +
   3.189 +   free(tmp);
   3.190 +   this->Size--;
   3.191 +
   3.192 +   return data;
   3.193 +   }
   3.194 +
   3.195 +
   3.196 +/*******************************************************************************
   3.197 + * Return the size of the list, or -1 is list is null.
   3.198 + */
   3.199 +int ll_size(LinkedList * this)
   3.200 +   {
   3.201 +   if (!this) return -1;
   3.202 +
   3.203 +   return this->Size;
   3.204 +   }
   3.205 +
   3.206 +
   3.207 +/*******************************************************************************
   3.208 + * Select the first element in the list if there is one.
   3.209 + * Return data pointer of new current element, or NULL is list is empty.
   3.210 + */
   3.211 +void * ll_head(LinkedList * this)
   3.212 +   {
   3.213 +   if (!this) return NULL;
   3.214 +
   3.215 +   this->Curr = this->Head;
   3.216 +
   3.217 +   if (this->Curr)
   3.218 +      return this->Curr->data;
   3.219 +   else
   3.220 +      return NULL;
   3.221 +   }
   3.222 +
   3.223 +
   3.224 +/*******************************************************************************
   3.225 + * Select the last element in the list if there is one.
   3.226 + * Return data pointer of new current element, or NULL is list is empty.
   3.227 + */
   3.228 +void * ll_tail(LinkedList * this)
   3.229 +   {
   3.230 +   if (!this) return NULL;
   3.231 +   
   3.232 +   this->Curr = this->Tail;
   3.233 +
   3.234 +   if (this->Curr)
   3.235 +      return this->Curr->data;
   3.236 +   else
   3.237 +      return NULL;
   3.238 +   }
   3.239 +
   3.240 +
   3.241 +/*******************************************************************************
   3.242 + * Select the next element in the list if there is one.
   3.243 + * Return data pointer of new current element, or NULL is list is empty.
   3.244 + */
   3.245 +void * ll_next(LinkedList * this)
   3.246 +   {
   3.247 +   if (!this) return NULL;
   3.248 +   
   3.249 +   if (this->Curr->next)
   3.250 +      this->Curr = this->Curr->next;
   3.251 +
   3.252 +   if (this->Curr)
   3.253 +      return this->Curr->data;
   3.254 +   else
   3.255 +      return NULL;
   3.256 +   }
   3.257 +
   3.258 +
   3.259 +/*******************************************************************************
   3.260 + * Select previous element in the list if there is one.
   3.261 + * Return data pointer of new current element, or NULL is list is empty.
   3.262 + */
   3.263 +void * ll_prev(LinkedList * this)
   3.264 +   {
   3.265 +   if (!this) return NULL;
   3.266 +
   3.267 +   if (this->Curr->prev)
   3.268 +      this->Curr = this->Curr->prev;
   3.269 +
   3.270 +   if (this->Curr)
   3.271 +      return this->Curr->data;
   3.272 +   else
   3.273 +      return NULL;
   3.274 +   }
   3.275 +
   3.276 +
   3.277 +/*******************************************************************************
   3.278 + * Return the data pointer of the current node, or NULL is list is empty.
   3.279 + */
   3.280 +void * ll_data(LinkedList * this)
   3.281 +   {
   3.282 +   if (!this) return NULL;
   3.283 +
   3.284 +   if (this->Curr)
   3.285 +      return this->Curr->data;
   3.286 +   else
   3.287 +      return NULL;
   3.288 +   }
   3.289 +
   3.290 +
   3.291 +/*******************************************************************************
   3.292 + * Constuctor.   Call this when creating a new list.
   3.293 + */ 
   3.294 +void ll_init(LinkedList * this)
   3.295 +   {
   3.296 +   if (this)
   3.297 +      {
   3.298 +      this->push   = ll_push;
   3.299 +      this->pop    = ll_pop;
   3.300 +      this->insert = ll_insert;
   3.301 +      this->remove = ll_remove;
   3.302 +      this->insert_at_head = ll_insert_at_head;
   3.303 +      this->size   = ll_size;
   3.304 +      this->head   = ll_head;
   3.305 +      this->tail   = ll_tail;
   3.306 +      this->next   = ll_next;
   3.307 +      this->prev   = ll_prev;
   3.308 +      this->data   = ll_data;
   3.309 +
   3.310 +      this->Head = this->Tail = this->Curr = NULL;
   3.311 +      this->Size = 0;
   3.312 +      }
   3.313 +   }
   3.314 +
   3.315 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/main.c	Wed Dec 29 02:14:35 2010 -0600
     4.3 @@ -0,0 +1,172 @@
     4.4 +/*******************************************************************************
     4.5 + * LinkedList
     4.6 + *
     4.7 + * A simple doubly linked list class in C.
     4.8 + *
     4.9 + *
    4.10 + * Test driver for LinkedList
    4.11 + *
    4.12 + ******************************************************************************/
    4.13 +
    4.14 +#include "LinkedList.h"
    4.15 +
    4.16 +#include <stdio.h>
    4.17 +#include <stdlib.h>
    4.18 +
    4.19 +
    4.20 +typedef struct mode_info mode_info;
    4.21 +struct mode_info
    4.22 +   {
    4.23 +   int          sizeid;
    4.24 +   int          w;
    4.25 +   int          h;
    4.26 +   int          r;
    4.27 +   };
    4.28 +
    4.29 +int main (int argc, char ** argv)
    4.30 +   {
    4.31 +   LinkedList list1;
    4.32 +   LinkedList list2;
    4.33 +
    4.34 +   int * p_int;
    4.35 +   mode_info * p_mode;
    4.36 +
    4.37 +   int i;
    4.38 +   int size;
    4.39 +
    4.40 +
    4.41 +   ll_init(&list1);
    4.42 +   ll_init(&list2);
    4.43 +
    4.44 +   for (i=0; i<10; ++i)
    4.45 +      {
    4.46 +      p_int = malloc(sizeof(int));
    4.47 +      *p_int = i;
    4.48 +      list1.push(&list1, p_int);
    4.49 +      }
    4.50 +   p_int = malloc(sizeof(int));
    4.51 +   *p_int = 17;
    4.52 +   list1.push(&list1, p_int);
    4.53 +
    4.54 +   list1.head(&list1);
    4.55 +   list1.next(&list1);
    4.56 +   p_int = malloc(sizeof(int));
    4.57 +   *p_int = 23;
    4.58 +   list1.insert(&list1, p_int);
    4.59 +
    4.60 +   list1.tail(&list1);
    4.61 +   p_int = malloc(sizeof(int));
    4.62 +   *p_int = 109;
    4.63 +   list1.insert(&list1, p_int);
    4.64 +
    4.65 +   list1.head(&list1);
    4.66 +   list1.next(&list1);
    4.67 +   list1.next(&list1);
    4.68 +   list1.next(&list1);
    4.69 +   list1.next(&list1);
    4.70 +   list1.next(&list1);
    4.71 +   free(list1.remove(&list1));
    4.72 +
    4.73 +   list1.head(&list1);
    4.74 +   free(list1.remove(&list1));
    4.75 +
    4.76 +   list1.tail(&list1);
    4.77 +   free(list1.remove(&list1));
    4.78 +
    4.79 +   list1.prev(&list1);
    4.80 +   list1.prev(&list1);
    4.81 +   free(list1.remove(&list1));
    4.82 +
    4.83 +   p_int = malloc(sizeof(int));
    4.84 +   *p_int = 77;
    4.85 +   list1.insert_at_head(&list1, p_int);
    4.86 +
    4.87 +
    4.88 +
    4.89 +   p_mode = calloc(1, sizeof(mode_info));
    4.90 +   p_mode->sizeid = 1;
    4.91 +   p_mode->w = 640;
    4.92 +   p_mode->h = 480;
    4.93 +   p_mode->r = 60;
    4.94 +   list2.push(&list2, p_mode);
    4.95 +
    4.96 +   p_mode = calloc(1, sizeof(mode_info));
    4.97 +   p_mode->sizeid = 2;
    4.98 +   p_mode->w = 800;
    4.99 +   p_mode->h = 600;
   4.100 +   p_mode->r = 85;
   4.101 +   list2.push(&list2, p_mode);
   4.102 +
   4.103 +   p_mode = calloc(1, sizeof(mode_info));
   4.104 +   p_mode->sizeid = 3;
   4.105 +   p_mode->w = 1024;
   4.106 +   p_mode->h = 768;
   4.107 +   p_mode->r = 72; 
   4.108 +   list2.push(&list2, p_mode);
   4.109 +
   4.110 +   p_mode = calloc(1, sizeof(mode_info));
   4.111 +   p_mode->sizeid = 4;
   4.112 +   p_mode->w = 1280;
   4.113 +   p_mode->h = 1024;
   4.114 +   p_mode->r = 60;
   4.115 +   list2.push(&list2, p_mode);
   4.116 +
   4.117 +
   4.118 +   printf("list2:\n");
   4.119 +
   4.120 +   list2.head(&list2);
   4.121 +   size = list2.size(&list2);
   4.122 +   for (i=0; i<size; ++i)
   4.123 +      {
   4.124 +      p_mode = list2.data(&list2);
   4.125 +      printf("mode %d: %dx%d @ %d MHz\n", 
   4.126 +	     p_mode->sizeid, p_mode->w, p_mode->h, p_mode->r);
   4.127 +      list2.next(&list2);
   4.128 +      }
   4.129 +   printf("\n\n");
   4.130 +
   4.131 +   size = list1.size(&list1);
   4.132 +   printf("List1 has %d elements\n", size);
   4.133 +   list1.head(&list1);
   4.134 +   for (i=0; i<size; ++i)
   4.135 +      {
   4.136 +      printf("%d ", *((int *) list1.data(&list1)) );
   4.137 +      fflush(stdout);
   4.138 +      list1.next(&list1);
   4.139 +      }
   4.140 +   printf("\n");
   4.141 +
   4.142 +   for (i=0; i<size; ++i)
   4.143 +      {
   4.144 +      p_int = list1.pop(&list1);
   4.145 +      printf("%d\n", *p_int);
   4.146 +      free(p_int);
   4.147 +      }
   4.148 +
   4.149 +
   4.150 +   LinkedList * list3;
   4.151 +   list3 = malloc(sizeof(LinkedList));
   4.152 +   if (!list3) 
   4.153 +      {
   4.154 +      printf("malloc failed!\n");
   4.155 +      exit(1);
   4.156 +      }
   4.157 +
   4.158 +   p_int = malloc(sizeof(int));
   4.159 +   *p_int = 21;
   4.160 +   ll_push(list3, p_int);
   4.161 +   p_int = malloc(sizeof(int));
   4.162 +   *p_int = 22;
   4.163 +   ll_push(list3, p_int);
   4.164 +   p_int = malloc(sizeof(int));
   4.165 +   *p_int = 23;
   4.166 +   ll_push(list3, p_int);
   4.167 +
   4.168 +   printf("\n\nlist3: ");
   4.169 +   for (i=0, size=ll_size(list3); i<size; ++i)
   4.170 +      {
   4.171 +      p_int = (int *) ll_pop(list3);
   4.172 +      printf("%d ", *p_int);
   4.173 +      }
   4.174 +   printf("\n");
   4.175 +   }