Welcome! Log In Create A New Profile

Advanced

Assignment 2 Question2(b)

Posted by Wiseguy 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Assignment 2 Question2(b)
February 23, 2009 03:11PM
How does the function required for this question differ from the one below ?
Language: C++
template<class Type> void linkedListType<Type>::deleteNode(const Type& deleteItem) { nodeType<Type> *current; //pointer to traverse the list nodeType<Type> *trailCurrent; //pointer just before current bool found;   if(first == NULL) //Case 1; list is empty. cerr<<"Can not delete from an empty list.\n"; else { if(first->info == deleteItem) //Case 2 { current = first; first = first->link; count--; if(first == NULL) //list has only one node last = NULL; delete current; } else //search the list for the node with the given info { found = false; trailCurrent = first; //set trailCurrent to point to //the first node current = first->link; //set current to point to the //second node   while(current != NULL && !found) { if(current->info != deleteItem) { trailCurrent = current; current = current->link; } else found = true; } // end while   if(found) //Case 3; if found, delete the node { trailCurrent->link = current->link; count--;   if(last == current) //node to be deleted was //the last node last = trailCurrent; //update the value of last   delete current; //delete the node from the list } else cout<<"Item to be deleted is not in the list."<<endl; } //end else } //end else } //end deleteNode
Doesn't this function already have the capabilty to delete a node when the user does a call such as:
deleteNode(deleteitem); .... where the variable "deleteitem" is an item in the list ??
avatar Re: Assignment 2 Question2(b)
February 23, 2009 05:03PM
Shit, you already started. I only got my book today.

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
avatar Re: Assignment 2 Question2(b)
February 24, 2009 08:02AM
Ok...blonde moment.
The function required for this exercise must delete all occurences ie. duplicates in the linked list whereas the function deleteNode only deletes a specific item in the list.
Go that out of the way now to get down to business.thumbs up smiley
Re: Assignment 2 Question2(b)
February 24, 2009 09:14AM
I'm still reading chapter 1 and trying to figure out big o notation.
Re: Assignment 2 Question2(b)
March 03, 2009 09:16PM
For Assignment 2 question 2

just a quick question , are you guys creating a derrived class from the base class linkedListType and then adding the extended functions to the new class, or are you just adding the extended functions to the existing linkedListType class ?
avatar Re: Assignment 2 Question2(b)
March 04, 2009 08:31AM
Quote:
"....just add(ing) the extended functions to the existing linkedListType class"
thumbs up smiley
Sorry, only registered users may post in this forum.

Click here to login