CISC 2200 Lecture Notes - Lecture 5: Memory Leak

0 views2 pages
user avatar
Published on 4 Jul 2020
School
Fordham University
Department
Computer and Information Sciences
Course
CISC 2200
Professor
DeleteItem
Void UnsortedType::DeleteItem(ItemType item)
{
NodeType* location = listData;
NodeType* templocation;
//Locate node to be deleted.
if(item.ComparedTo(listData ->info) == EQUAL)
{
Templocation = location;
listData = listData -> next; //Delete first node
}
Else
{
while(item.ComparedTo(location->next)->info) != EQUAL)
Location = location -> next;
//Delete node at location ->next
tempLocation = location -> next;
location->next = (location ->next)->next;
}
Delete templocation;
Length--;
}
//rewriting code Prof. made
Void Unsorted::DeleteItem(ItemType item)
{
NodeType * p = listData; //special case: pred is null & listData points to it
NodeType *pred = NULL;
While (item.CompareTo(p-> info) != EQUAL)
{ Pred = p;
P = p ->next;
}
If (pred == NULL) {listData = listData -> next;}
Else {
pred->next = p->next;
Delete p;
Length--;}
}
Iterators
The array-based implementation used currentPos, an array index
Linked Lists used a pointer to a node instead
GetNextItem advances it: currentPos -> next
Void UnsortedType::ResetList()
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in