Oh.
I've been staring at this for so long I've stopped recognizing error messages. I initialized cvalue to 0.
I'm sure I'll be back on in a few minutes.
Oh.
I've been staring at this for so long I've stopped recognizing error messages. I initialized cvalue to 0.
I'm sure I'll be back on in a few minutes.
I have a new unhandled exception, and I think it's coming from my insert function which is defined as follows:
It might be helpful to know how I typedef my pointers:Code:void CDeck::insert(int index, s_card c) { if(empty()||index==1) { insertAtHead(c); } else { cardNodeptr cur = head; cardNodeptr prev = NULL; for(int x=1; x<=index; x++) { prev = cur; cur = cur->next; } cardNodeptr newPtr = cur; newPtr->item = c; } } void CDeck::insertAtHead(s_card c) { cardNodeptr cur = new cardNode; cur->next = head; cur->item = c; head = cur; }
And I did define cardNode *head as a private data member.Code:struct s_card { int value; char suit; }; struct cardNode { s_card item; cardNode *next; }; typedef cardNode * cardNodeptr;
Last edited by marQade; 05-16-2008 at 01:47 PM. Reason: See when I learn this, I'll never forget how LL's work.
Where is the guarantee that this loop won't attempt to go beyond the end of the list?
What is the purpose of this function? Does it insert new nodes or does it modify the contents of existing nodes? I think you should pick one of those, do that well, and perhaps rename the function to reflect what it does if you decide it shouldn't actually insert nodes.Code:cardNodeptr cur = head; cardNodeptr prev = NULL; for(int x=1; x<=index; x++) { prev = cur; cur = cur->next; }
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.