Linked List

Reply

Join Date: May 2005
Posts: 42
Reputation: TimC is an unknown quantity at this point 
Solved Threads: 0
TimC TimC is offline Offline
Light Poster

Linked List

 
0
  #1
Nov 30th, 2005
Dear All.

I have a small problem with the code attached. I am trying to add an object to a linked list. When I try to compile I am getting an error. For the life of me I cant figure out the error. this is after 5hrs of head wrecking searching. Any help would be greatly appreciated. thx in advance Tim.
Attached Files
File Type: zip christmas2.zip (3.9 KB, 8 views)
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16
Reputation: HyperEngineer is an unknown quantity at this point 
Solved Threads: 0
HyperEngineer HyperEngineer is offline Offline
Newbie Poster

Re: Linked List

 
0
  #2
Nov 30th, 2005
Tim,

I only time to look at one file. In Sequence.cpp I found this function. I believe this may cause a problem if the index is not valid.

  1. SeqItemType Sequence::retrieve(int index)
  2. {
  3. if ((index < 1) || (index > size())){
  4. // can't delete something that isn't there
  5. }
  6. ListNode *cur = find(index);
  7. return cur->item;
  8. }

If the expression in the if statement is true it will still do the last bit of code, unless you wanted and if-else structure.
The find(index) will return zero if index is not valid. Then when it tries to resolve cur->item, that might give you a problem. Look at your code and see if you are ever returning 0 that will be used in a cur->item context. Check for 0. If it is, return or move on without doing anything.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 238
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Linked List

 
0
  #3
Nov 30th, 2005
One would be the missing semicolon in "Sequence.h":
typedef patient SeqItemType;
Others are things like returning a pointer from a function that is not declared as returning a pointer.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC