| | |
Linked List
![]() |
•
•
Join Date: May 2005
Posts: 42
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Apr 2005
Posts: 16
Reputation:
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.
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.
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.
C Syntax (Toggle Plain Text)
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.
One would be the missing semicolon in "Sequence.h":
Others are things like returning a pointer from a function that is not declared as returning a pointer.
typedef patient SeqItemType; "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
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- help implementing singly linked list (C++)
- How to read in a sentence and insert in to linked list? (C++)
- Linked List using pointers (C++ ADT) (C++)
- Why doesn't this remove the last node in a linked list? (C++)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- Linked List (C++)
- help by sorting a simply linked list (C)
Other Threads in the C Forum
- Previous Thread: need you wise advices...
- Next Thread: project question?
| Thread Tools | Search this Thread |
* adobe api array arrays bash binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o ide inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling scripting segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






