Re: can someone please help me with making this class
- From: sparks <jobob@xxxxxxxx>
- Date: Sun, 26 Mar 2006 21:41:50 GMT
I guess the weirdest thing is this works.
Not completly because as you pointed out I did
not have the else to get it to completly
insert all the nodes.
Jerry
I made a new project and 2 .h files one node class that I made out of the
struct and another I put the insert in.
And no longer have the errors that I was seeing.
I am not sure if adding the .h to the existing project and doing the same thing
got it confused or what. But I am not finished but it seems to be doing better.
On Sun, 26 Mar 2006 10:49:40 -0800, Barry Schwarz <schwarzb@xxxxxxxxx> wrote:
On Sat, 25 Mar 2006 18:37:28 GMT, sparks <jobob@xxxxxxxx> wrote:.
I wrote a program for linked list(I have included the insert routine)
this works fine.
Only for some strange definition of fine.
======================================================
struct node
{
string Drname;
string phoneNo;
node *nxt;
};
node *start_ptr = NULL;
node *current;
int option = 0;
//sorted insert in list
void insert_node(string name, string phone)
{
node *temp, *prev ;
temp = new node;
prev = new node;
temp->Drname = name;
temp->phoneNo = phone;
temp->nxt = NULL;
prev->nxt = NULL;
if (start_ptr == NULL)
{
start_ptr = temp;
current = start_ptr;
}
else
{
temp=start_ptr;
Didn't you just lose the first structure you created with new and
initialized above?
prev=NULL;
And the second?
if (temp->phoneNo < start_ptr->phoneNo)
Since temp == start_ptr, can this ever be true?
{
temp->nxt = start_ptr;
start_ptr->nxt = NULL;
}
else
{
while((temp->nxt != NULL) && (temp->phoneNo < current->phoneNo))
{
prev->nxt = temp;
prev was set to NULL. You cannot dereference it. Even if you could,
you never update prev in this while loop so you continue to change the
same prev->nxt repeatedly.
temp = temp -> nxt;
}
temp->nxt = current;
prev->nxt = temp;
}
}
cout<<current->Drname<<endl;
Where in the "else block" did current ever get updated?
}
Remove del for email
- References:
- can someone please help me with making this class
- From: sparks
- Re: can someone please help me with making this class
- From: Barry Schwarz
- can someone please help me with making this class
- Prev by Date: Re: not a warning?
- Next by Date: Design orientated 'C' question
- Previous by thread: Re: can someone please help me with making this class
- Next by thread: Re: BSTR, _bstr_t issues occuring on our Windows 2003 Server
- Index(es):
Relevant Pages
|