954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Linked List

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.

Attachments christmas2.zip (3.88KB)
TimC
Light Poster
42 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

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.

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


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.

HyperEngineer
Newbie Poster
16 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

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.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You