Re: can someone please help me with making this class
- From: Barry Schwarz <schwarzb@xxxxxxxxx>
- Date: Sun, 26 Mar 2006 10:49:40 -0800
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
.
- Follow-Ups:
- References:
- can someone please help me with making this class
- From: sparks
- can someone please help me with making this class
- Prev by Date: Re: not a warning?
- Next by Date: Re: not a warning?
- Previous by thread: can someone please help me with making this class
- Next by thread: Re: can someone please help me with making this class
- Index(es):
Relevant Pages
|