Re: can someone please help me with making this class



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
.



Relevant Pages

  • Re: can someone please help me with making this class
    ... struct and another I put the insert in. ... string phoneNo; ... node *temp, *prev; ...
    (microsoft.public.vc.language)
  • RE: Q: define values for all pages
    ... string Name = dt.Name; ... Where temp is the class created. ... > struct and use it in the myStruct.myFirstvalie, MyStruct.SecondValue, how ... Prev by Date: ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: FileSearch to locate the latest (last saved) file
    ... Dim sReport As Workbook, sDashboard As Workbook ... Dim fLdr As String, Fil As String, FPath As String, x As String, _ ... FileDates= temp ... For i = 1 To NewestFile ...
    (microsoft.public.excel.programming)
  • Re: locating strings approximately
    ... > I'd like to see if a string exists, even approximately, in another. ... > have looked at edit distance, but that isn't a good choice for finding ... if temp < dist: dist = temp ... dprev, dcurr = dcurr, dprev ...
    (comp.lang.python)
  • Re: Unmanaged code(dll) function: int myfunc (char* temp)
    ... //Assigning an value to temp ... I am using char* not TCHAR* ... Can you help me how to get the value of temp when using string builder ... int myfunc ...
    (microsoft.public.dotnet.framework.compactframework)