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.
Fork of LinkedList by
Diff: LinkedList.cpp
- Revision:
- 3:c14e7a918e21
- Parent:
- 1:a032c0392ba1
- Child:
- 4:59b2aa82b517
--- a/LinkedList.cpp Fri Apr 05 23:44:10 2013 +0000
+++ b/LinkedList.cpp Mon Apr 08 22:23:25 2013 +0000
@@ -133,17 +133,17 @@
retT *current = _head;
retT *prev = 0;
// make sure we have an item to remove
- if (loc < length())
+ if ((loc < length()) && (loc > 0))
{
// move to the item we want to delete
- if (0 == loc)
+ if (1 == loc)
{
_head = current->next;
delete [] current;
}
else
{
- for (uint32_t i=0; i<loc; ++i)
+ for (uint32_t i=2; i<=loc; ++i)
{
prev = current;
current = current->next;
@@ -162,12 +162,12 @@
{
retT *current = _head;
// make sure we have something in the location
- if (loc > length())
+ if ((loc > length()) || (loc == 0))
{
return 0;
}
// and if so jump down the list
- for (uint32_t i=0; i<loc; ++i)
+ for (uint32_t i=2; i<=loc; ++i)
{
current = current->next;
}
@@ -178,12 +178,12 @@
template<class retT>
uint32_t LinkedList<retT>::length(void)
{
- int count = 0;
+ int32_t count = 0;
retT *current = _head;
//loop until the end of the list is found
while (current != 0)
{
- count++;
+ ++count;
current = current->next;
}
