]> git.mdlowis.com Git - projs/libcds.git/commitdiff
Fixed bug in LL_Get and added LL_Length function
authorMike D. Lowis <mike@mdlowis.com>
Fri, 3 Jun 2011 16:38:56 +0000 (12:38 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Fri, 3 Jun 2011 16:38:56 +0000 (12:38 -0400)
src/linked_list/linked_list.c
src/linked_list/linked_list.h

index 3cab7bbba6697ed7e19b843fe2154f6bfc012fb0..a0df8acd09b4fe9c712b9b9825f38b2537279279 100644 (file)
@@ -43,7 +43,7 @@ LinkedList_T* LL_Get( LinkedList_T* list, int index )
        int current = 0;
        LinkedList_T* node = list;
        LinkedList_T* indexed_node = NULL;
-       while ((node != NULL) && (node->next != NULL))
+       while ((node != NULL))
        {
                if ( current == index )
                {
@@ -106,3 +106,14 @@ void LL_Free( LinkedList_T* list, BOOL free_contents)
        }
 }
 
+U32 LL_Length(LinkedList_T* list)
+{
+       U32 length = 0;
+       LinkedList_T* item = list;
+       for ( item = list; item != NULL; item = item->next )
+       {
+               length++;       
+       }
+       return length;
+}
+
index 881b1aa8192831ca822c695e680bc4c54fb6a7f7..551a1dae0dc69834ccb7bc9d44f479cfdeece289 100644 (file)
@@ -104,6 +104,16 @@ void LL_Delete( LinkedList_T* list, int index, BOOL free_contents);
  * */
 void LL_Free( LinkedList_T* list, BOOL free_contents);
 
-#define LL_FOREACH(item,list) for( item = list; item != NULL; item = item->next )
+/**
+ * @brief Returns the number of elements in the list.
+ * 
+ * Loops through the supplied list and returns a count of the number of elements
+ * contained in the list.
+ *
+ * @param list        The list to be counted.
+ *
+ * @return The number of elements in the list.
+ **/
+U32 LL_Length(LinkedList_T* list);
 
 #endif