Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Waldo_Embed_V2 elevator_with_queue RaheeNew DS1820 ... more
Revision 1:a032c0392ba1, committed 2013-04-05
- Comitter:
- sam_grove
- Date:
- Fri Apr 05 23:14:49 2013 +0000
- Parent:
- 0:3f64a15357ac
- Child:
- 2:704e1c9057c1
- Commit message:
- Pulled in from an offline project. Member insert needs some work. Updated documentation
Changed in this revision
| LinkedList.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LinkedList.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LinkedList.cpp Thu Apr 04 20:34:38 2013 +0000
+++ b/LinkedList.cpp Fri Apr 05 23:14:49 2013 +0000
@@ -21,12 +21,14 @@
*/
#include "LinkedList.h" // api wrapper
+#include "LogUtil.h"
template<class retT>
LinkedList<retT>::LinkedList()
{
// clear the members
_head = 0;
+ _head->next = 0;
return;
}
@@ -50,8 +52,7 @@
// make sure the new object was allocated
if (0 == new_node)
{
- // output an error message here
- //error( DBG_MSG("Memory Allocation Failed") );
+ ERROR("Memory allocation failed\n");
}
// update the next item in the list to the current head
new_node->next = _head;
@@ -62,36 +63,35 @@
return _head;
}
-template<class retT>
-retT *LinkedList<retT>::insert(void *data, uint32_t loc)
-{
- retT *new_node = new retT [1];
- // make sure the new object was allocated
- if (0 == new_node)
- {
- // output an error message here
- //error( DBG_MSG("Memory Allocation Failed") );
- }
- retT *current = _head->next;
- retT *prev = _head;
- // move to the item we want to insert
- for (uint32_t i=1; i!=(loc-1); i++)
- {
- prev = current;
- current = current->next;
- }
- // store the address to the linked datatype
- new_node->data = data;
- // clear the next pointer
- new_node->next = 0;
- // update the list and store the new stuff
- prev->next = new_node;
- new_node->next = current;
- // store the address to the linked datatype
- _head->data = data;
-
- return prev->next;
-}
+//template<class retT>
+//retT *LinkedList<retT>::insert(void *data, uint32_t loc)
+//{
+// retT *new_node = new retT [1];
+// // make sure the new object was allocated
+// if (0 == new_node)
+// {
+// ERROR("Memory allocation failed\n");
+// }
+// retT *current = _head->next;
+// retT *prev = _head;
+// // move to the item we want to insert
+// for (uint32_t i=1; i!=(loc-1); i++)
+// {
+// prev = current;
+// current = current->next;
+// }
+// // store the address to the linked datatype
+// new_node->data = data;
+// // clear the next pointer
+// new_node->next = 0;
+// // update the list and store the new stuff
+// prev->next = new_node;
+// new_node->next = current;
+// // store the address to the linked datatype
+// _head->data = data;
+//
+// return prev->next;
+//}
template<class retT>
retT *LinkedList<retT>::append(void *data)
@@ -101,8 +101,7 @@
// make sure the new object was allocated
if (0 == new_node)
{
- // output an error message here
- //error( DBG_MSG("Memory Allocation Failed") );
+ ERROR("Memory allocation failed\n");
}
// store the address to the linked datatype
new_node->data = data;
@@ -132,19 +131,19 @@
retT *LinkedList<retT>::remove(uint32_t loc)
{
retT *current = _head;
- retT *prev;
+ retT *prev = 0;
// make sure we have an item to remove
- if (loc <= length())
+ if (loc < length())
{
// move to the item we want to delete
- if (1 == loc)
+ if (0 == loc)
{
_head = current->next;
delete [] current;
}
else
{
- for (uint32_t i=1; i!=loc; i++)
+ for (uint32_t i=0; i<loc; ++i)
{
prev = current;
current = current->next;
@@ -168,7 +167,7 @@
return 0;
}
// and if so jump down the list
- for (uint32_t i=1; i!=loc; i++)
+ for (uint32_t i=0; i<loc; ++i)
{
current = current->next;
}
@@ -191,7 +190,7 @@
return count;
}
-// pre-define the templated instance for the linker
+// pre-define the type for the linker
template class LinkedList<node>;
--- a/LinkedList.h Thu Apr 04 20:34:38 2013 +0000
+++ b/LinkedList.h Fri Apr 05 23:14:49 2013 +0000
@@ -26,7 +26,7 @@
#include <stdint.h>
/**
- * @enum node
+ * @struct node
* @brief The Linked List structure
*/
struct node
@@ -36,12 +36,31 @@
};
/** Example using the LinkedList Class
- *
- * Example:
* @code
* int main(void)
- * {
- * }
+ * #include "mbed.h"
+ * #include "LinkedList.h"
+ *
+ * LinkedList<node>list;
+ *
+ * int main()
+ * {
+ * node *tmp;
+ *
+ * list.push((char *)"Two\n");
+ * list.append((char *)"Three\n");
+ * list.append((char *)"Four\n");
+ * list.push((char*)"One\n");
+ * list.append((char*)"Five\n");
+ *
+ * for(int i=0; i<list.length(); i++)
+ * {
+ * tmp = list.pop(i);
+ * printf("%s", (char *)tmp->data);
+ * }
+ *
+ * error("done\n");
+ * }
* @endcode
*/
@@ -71,12 +90,12 @@
*/
retT *push(void *data);
- /** Add a member to some position in the list
- * @param data - Some data type that is added to the list
- * @param loc - Place in the list to put the data
- * @return The member that was just inserted (NULL if empty)
- */
- retT *insert(void *data, uint32_t loc);
+// /** Add a member to some position in the list
+// * @param data - Some data type that is added to the list
+// * @param loc - Place in the list to put the data
+// * @return The member that was just inserted (NULL if empty)
+// */
+// retT *insert(void *data, uint32_t loc);
/** Add a member to the end of the list
* @param data - Some data type that is added to the list