473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with linked list ..

Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include "GenericStringClass2.h"
#include <string.h>
#define DEFAULT 0

class MACListPart
{
public:
// constructor
MACListPart();
~MACListPart();
MACListPart *GetNextPointer();
private:
friend class MACList;
String macAdr;
int data;
MACListPart *next;
};
class MACList
{
public:
//constructors
MACList();
~MACList();

//accessors
void PrintList(void);
void AddNode(const String& mac);
void DeleteNode(const String& mac);
bool FindNode(const String&);
// void DeleteList();
bool IsListEmpty();
int GetCount(void);

protected:
MACListPart *head;
MACListPart *current;

private:
int itsCount;
};

MACListPart::MACListPart(void)
{
next=NULL;
data=0;

// macAdr=..
}
MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";
if(this != NULL)
{

delete this;
}
else delete this;
}

MACListPart* MACListPart::GetNextPointer(void)
{
if(this==NULL)
{
cout << "You are pointing to nowhere , where do you
think you are going ??\n";
return NULL;
}
else
{
return this->next;
}
}
MACList::MACList(void)
{
head=NULL;
current=NULL;
itsCount=0;
}
MACList::~MACList(void)
{/*
if(IsListEmpy()==true)
{
//do nothing ..
}
else
{
DeleteList();
}*/
}

bool MACList::IsListEmpty(void)
{
if(head==NULL)
{
return true;
}

//else ....
return false;
}
bool MACList::FindNode(const String& mac)
{
MACListPart *pMacListPart=head;
while(pMacListPart !=NULL)
{
if(pMacListPart->macAdr==mac)
{
return true;
}
}
return false;
}
int MACList::GetCount(void)
{
return itsCount;
}
void MACList::AddNode(const String& mac)
{
MACListPart *pMACListPart = new MACListPart;
pMACListPart->macAdr=mac;
pMACListPart->data=DEFAULT;
pMACListPart->next=NULL;

if(IsListEmpty() == true)
{
head=pMACListPart;
current=head;
}
else // (if IsListEmpty() == false )
{
current->next=pMACListPart;
current=pMACListPart;
}
// increasing the elements of the list
itsCount++;
}


void MACList::PrintList()
{
MACListPart *temp = head;
while( temp != NULL)
{
cout << temp->macAdr.GetString() << endl;
temp=temp->next;
}
}
void MACList::DeleteNode(const String& mac)
{
char c;
// If the first element of the list is going to be deleted:
if(head->macAdr==mac)
{
MACListPart *tempNode;
tempNode=head->next;
delete head;
head=tempNode;
}
else
{
MACListPart *prevNode,*currNode;
prevNode=head;
currNode=head->next;
while(currNode != NULL)
{
if(currNode->macAdr==mac)
{
MACListPart *tempNode;
tempNode=currNode->next;
prevNode->next=tempNode;
printf("YAHOOOO\n");
this->PrintList();
c=getchar();
delete currNode;

}
else // you didn't find the string in currNode
so ...
{
prevNode=currNode;
currNode=currNode->next;
}
}
}
}
int main(void)
{
MACList MACListIstance;
MACListIstance.AddNode("11-11-11-11-11-11");
MACListIstance.AddNode("22-22-22-22-22-22");
MACListIstance.AddNode("33-33-33-33-33-33");
MACListIstance.AddNode("44-44-44-44-44-44");
MACListIstance.PrintList();
bool t = MACListIstance.FindNode("11-11-11-11-11-11");
MACListIstance.DeleteNode("22-22-22-22-22-22");
MACListIstance.PrintList();
if (t==true) cout << "This MAC address exists into the
database ... \n";
else cout << "This MAC address does not exist in the
database.... \n";
cout << "Hello world ... the list currently has " <<
MACListIstance.GetCount() << " elements \n";
return 0;
}
The problem is when i am trying to delete a node .. The program hangs
after the command
delete currNode is executed ... The String class is declared in
another file and here is the
default destructor :
String::~String()
{
cout << "Calling the default destructor of String ..\n";
delete [] itsString;
itsLen=0;
cout <<"Default destructor of String finished ... \n";
}
Can you help ?? I am using Visual C++

(Sorry for my english ... )
Jul 22 '05 #1
11 1353

"Andrew Skouloudis" <af********************@yahoo.com> wrote in message
news:o8********************************@4ax.com...
Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...
class MACListPart
{
public:
// constructor
MACListPart();
~MACListPart();
MACListPart *GetNextPointer();
private:
friend class MACList;
String macAdr;
int data;
MACListPart *next;
};

MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";
/*
if(this != NULL)
{

delete this;
}
else delete this;
*/
}

You don't need to write destructor for MACListPart. If you do... you don't
want to do the suicide thing...

Remember to decrement itsCount in the

void MACList::DeleteNode (const String &mac) function and you'll get...

11-11-11-11-11-11
22-22-22-22-22-22
33-33-33-33-33-33
44-44-44-44-44-44
YAHOOOO
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44
This MAC address exists into the database ...
Hello world ... the list currently has 3 elements

Is that what you wanted?

Can you help ?? I am using Visual C++

(Sorry for my english ... )


Regards

Brian
Jul 22 '05 #2
On Sun, 28 Dec 2003 12:22:14 -1000, "Brian MacBride"
<ma******@ix.netcom.com> wrote:

"Andrew Skouloudis" <af********************@yahoo.com> wrote in message
news:o8********************************@4ax.com.. .
Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...
class MACListPart
{
public:
// constructor
MACListPart();
~MACListPart();
MACListPart *GetNextPointer();
private:
friend class MACList;
String macAdr;
int data;
MACListPart *next;
};

MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";


/*
if(this != NULL)
{

delete this;
}
else delete this;


*/
}


You don't need to write destructor for MACListPart. If you do... you don't
want to do the suicide thing...

Remember to decrement itsCount in the

void MACList::DeleteNode (const String &mac) function and you'll get...

11-11-11-11-11-11
22-22-22-22-22-22
33-33-33-33-33-33
44-44-44-44-44-44
YAHOOOO
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44
This MAC address exists into the database ...
Hello world ... the list currently has 3 elements

Is that what you wanted?

Can you help ?? I am using Visual C++

(Sorry for my english ... )


Regards

Brian

First of all thank you for your answer
Secondly .. how did you do that ??

I did put

if(this != NULL)
{

delete this;
}
else delete this;

in comments and still the program hangs !! Can you give me the
destructor of your String class ????
I even removed the destructor definition in the MACListPart , so the
compiler should do whatever it want to, when deleting the node .
But still nothing !!! .

This is the output of my program :

Calling the default destructor of String ..
Default destructor of called ...
Calling the default destructor of String ..
Default destructor of called ...
Calling the default destructor of String ..
Default destructor of called ...
Calling the default destructor of String ..
Default destructor of called ...
11-11-11-11-11-11
22-22-22-22-22-22
33-33-33-33-33-33
44-44-44-44-44-44
YAHOOOO
Calling the default destructor of String ..
Default destructor of called ...
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44 // And now hangs !!!
Jul 22 '05 #3

"Andrew Skouloudis" <af********************@yahoo.com> wrote in message
news:h7********************************@4ax.com...
On Sun, 28 Dec 2003 12:22:14 -1000, "Brian MacBride"
<ma******@ix.netcom.com> wrote:

"Andrew Skouloudis" <af********************@yahoo.com> wrote in message
news:o8********************************@4ax.com.. .
Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...
class MACListPart
{
public:
// constructor
MACListPart();
~MACListPart();
MACListPart *GetNextPointer();
private:
friend class MACList;
String macAdr;
int data;
MACListPart *next;
};

MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";


/*
if(this != NULL)
{

delete this;
}
else delete this;


*/
}


You don't need to write destructor for MACListPart. If you do... you don'twant to do the suicide thing...

Remember to decrement itsCount in the

void MACList::DeleteNode (const String &mac) function and you'll get...

11-11-11-11-11-11
22-22-22-22-22-22
33-33-33-33-33-33
44-44-44-44-44-44
YAHOOOO
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44
This MAC address exists into the database ...
Hello world ... the list currently has 3 elements

Is that what you wanted?

Can you help ?? I am using Visual C++

(Sorry for my english ... )


Regards

Brian

First of all thank you for your answer
Secondly .. how did you do that ??

I did put

if(this != NULL)
{

delete this;
}
else delete this;

in comments and still the program hangs !! Can you give me the
destructor of your String class ????
I even removed the destructor definition in the MACListPart , so the
compiler should do whatever it want to, when deleting the node .
But still nothing !!! .

This is the output of my program :

Calling the default destructor of String ..
Default destructor of called ...
Calling the default destructor of String ..
Default destructor of called ...
Calling the default destructor of String ..
Default destructor of called ...
Calling the default destructor of String ..
Default destructor of called ...
11-11-11-11-11-11
22-22-22-22-22-22
33-33-33-33-33-33
44-44-44-44-44-44
YAHOOOO
Calling the default destructor of String ..
Default destructor of called ...
11-11-11-11-11-11
33-33-33-33-33-33
44-44-44-44-44-44 // And now hangs !!!


You didn't forget that you have this silly....

c = getchar ();

....here. Lose it...

Regards

Brian

Jul 22 '05 #4

You didn't forget that you have this silly....

c = getchar ();

...here. Lose it...

Regards

Brian


I am not THAT stupid ... When I i say it hangs i mean that the
execution of the program stops and Windows XP creates a window
which says that " LinkedList3.exe has encourted a problem and needs
to close . We are sorry for the inconvenience " blah-blah .. Debug ,
Send Report , Don't Send ". The problem is with the delete operation .
Did you run this program with VC++ ??? . What's your String destructor
???
Jul 22 '05 #5
Andrew Skouloudis wrote:
Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h> iostream.h is not standard so use:
#include <iostream>
and for the time being
using namespace std;
#include "GenericStringClass2.h"
#include <string.h>
#define DEFAULT 0

class MACListPart
{
public:
// constructor
MACListPart();
~MACListPart();
MACListPart *GetNextPointer();
private:
friend class MACList;
String macAdr;
int data;
MACListPart *next;
};
class MACList
{
public:
//constructors
MACList();
~MACList();

//accessors
void PrintList(void);
void AddNode(const String& mac);
void DeleteNode(const String& mac);
bool FindNode(const String&);
// void DeleteList();
bool IsListEmpty();
int GetCount(void);

protected:
MACListPart *head;
MACListPart *current;

private:
int itsCount;
};

MACListPart::MACListPart(void)
{
next=NULL;
data=0;

// macAdr=..
}
MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";
if(this != NULL)
{

delete this;
}
else delete this; This is quite a strange piece of code as it is equivalent to "delete
this". It is not needed. }

MACListPart* MACListPart::GetNextPointer(void)
{
if(this==NULL)
If this is NULL you have problems, therefore this check is completely
unneeded. Do the NULL check where you use this method.
{
cout << "You are pointing to nowhere , where do you
think you are going ??\n";
return NULL;
}
else
{
return this->next;
}
}
MACList::MACList(void)
{
head=NULL;
current=NULL;
itsCount=0;
}
MACList::~MACList(void)
{/*
if(IsListEmpy()==true)
{
//do nothing ..
}
else
{
DeleteList();
}*/
}

bool MACList::IsListEmpty(void)
{
if(head==NULL)
{
return true;
}

//else ....
return false;
}
bool MACList::FindNode(const String& mac)
{
MACListPart *pMacListPart=head;
while(pMacListPart !=NULL)
{
if(pMacListPart->macAdr==mac)
{
return true;
}
}
return false;
}
int MACList::GetCount(void)
{
return itsCount;
}
void MACList::AddNode(const String& mac)
{
MACListPart *pMACListPart = new MACListPart;
pMACListPart->macAdr=mac;
pMACListPart->data=DEFAULT;
pMACListPart->next=NULL;

if(IsListEmpty() == true)
{
head=pMACListPart;
current=head;
}
else // (if IsListEmpty() == false )
{
current->next=pMACListPart;
current=pMACListPart;
}
// increasing the elements of the list
itsCount++;
}


void MACList::PrintList()
{
MACListPart *temp = head;
while( temp != NULL)
{
cout << temp->macAdr.GetString() << endl;
temp=temp->next;
}
}
void MACList::DeleteNode(const String& mac)
{
char c;
// If the first element of the list is going to be deleted:
if(head->macAdr==mac)
{
MACListPart *tempNode;
tempNode=head->next;
delete head;
head=tempNode;
}
else
{
MACListPart *prevNode,*currNode;
prevNode=head;
currNode=head->next;
while(currNode != NULL)
{
if(currNode->macAdr==mac)
{
MACListPart *tempNode;
tempNode=currNode->next;
prevNode->next=tempNode;
printf("YAHOOOO\n");
this->PrintList();
c=getchar();
delete currNode;

The reason it crashes is because you dont exit the loop. Just add a
break; here. Or if you want to delete all nodes that match update
prevNode and currNode.

Mike
Jul 22 '05 #6
On Mon, 29 Dec 2003 13:16:29 +0000, Michael Mellor
<news-at-@michaelmellor-dot-.com> wrote:
Andrew Skouloudis wrote:
Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>

iostream.h is not standard so use:
#include <iostream>
and for the time being
using namespace std;
#include "GenericStringClass2.h"
#include <string.h>
#define DEFAULT 0

class MACListPart
{
public:
// constructor
MACListPart();
~MACListPart();
MACListPart *GetNextPointer();
private:
friend class MACList;
String macAdr;
int data;
MACListPart *next;
};
class MACList
{
public:
//constructors
MACList();
~MACList();

//accessors
void PrintList(void);
void AddNode(const String& mac);
void DeleteNode(const String& mac);
bool FindNode(const String&);
// void DeleteList();
bool IsListEmpty();
int GetCount(void);

protected:
MACListPart *head;
MACListPart *current;

private:
int itsCount;
};

MACListPart::MACListPart(void)
{
next=NULL;
data=0;

// macAdr=..
}
MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";
if(this != NULL)
{

delete this;
}
else delete this;

This is quite a strange piece of code as it is equivalent to "delete
this". It is not needed.
}

MACListPart* MACListPart::GetNextPointer(void)
{
if(this==NULL)


If this is NULL you have problems, therefore this check is completely
unneeded. Do the NULL check where you use this method.
{
cout << "You are pointing to nowhere , where do you
think you are going ??\n";
return NULL;
}
else
{
return this->next;
}
}
MACList::MACList(void)
{
head=NULL;
current=NULL;
itsCount=0;
}
MACList::~MACList(void)
{/*
if(IsListEmpy()==true)
{
//do nothing ..
}
else
{
DeleteList();
}*/
}

bool MACList::IsListEmpty(void)
{
if(head==NULL)
{
return true;
}

//else ....
return false;
}
bool MACList::FindNode(const String& mac)
{
MACListPart *pMacListPart=head;
while(pMacListPart !=NULL)
{
if(pMacListPart->macAdr==mac)
{
return true;
}
}
return false;
}
int MACList::GetCount(void)
{
return itsCount;
}
void MACList::AddNode(const String& mac)
{
MACListPart *pMACListPart = new MACListPart;
pMACListPart->macAdr=mac;
pMACListPart->data=DEFAULT;
pMACListPart->next=NULL;

if(IsListEmpty() == true)
{
head=pMACListPart;
current=head;
}
else // (if IsListEmpty() == false )
{
current->next=pMACListPart;
current=pMACListPart;
}
// increasing the elements of the list
itsCount++;
}


void MACList::PrintList()
{
MACListPart *temp = head;
while( temp != NULL)
{
cout << temp->macAdr.GetString() << endl;
temp=temp->next;
}
}
void MACList::DeleteNode(const String& mac)
{
char c;
// If the first element of the list is going to be deleted:
if(head->macAdr==mac)
{
MACListPart *tempNode;
tempNode=head->next;
delete head;
head=tempNode;
}
else
{
MACListPart *prevNode,*currNode;
prevNode=head;
currNode=head->next;
while(currNode != NULL)
{
if(currNode->macAdr==mac)
{
MACListPart *tempNode;
tempNode=currNode->next;
prevNode->next=tempNode;
printf("YAHOOOO\n");
this->PrintList();
c=getchar();
delete currNode;

The reason it crashes is because you dont exit the loop. Just add a
break; here. Or if you want to delete all nodes that match update
prevNode and currNode.

Mike


Yes that's it .. THANK YOU SO MUCH !!!!!!!!!!!!!!!
Jul 22 '05 #7

"Andrew Skouloudis" <af********************@yahoo.com> wrote in message
news:7a********************************@4ax.com...

You didn't forget that you have this silly....

c = getchar ();

...here. Lose it...

Regards

Brian
I am not THAT stupid ...


I didn't mean to imply that you were. I often overlook the obvious at
times. Sometimes I can't see the forest for the trees. ;-)
When I i say it hangs i mean that the
execution of the program stops and Windows XP creates a window
which says that " LinkedList3.exe has encourted a problem and needs
to close . We are sorry for the inconvenience " blah-blah .. Debug ,
Send Report , Don't Send ". The problem is with the delete operation .
One of the things that would give me that message is running out of stack
space.

This...

MACListPart::~MACListPart (void) {
cout << "Calling the default destructor for MACListPart ...\n";
if (this != NULL)
delete this;
else
delete this;
}

.... will set up an endless loop and would have caused that.that message for
me.
Did you run this program with VC++ ???.
....and two others... g++ amd Borland
What's your String destructor
???


Well I don't have your String class but your d'tor looks OK and would have
worked for you elsewhere in your program.

I used std::string, implemented thus...

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
// #include "GenericStringClass2.h"
#include <string.h>

// Emulate 'class String'
#include <string>
typedef std::string String;
#define GetString c_str

#define DEFAULT 0

<snip>

,,,You could try that.

Regards

Brian
Jul 22 '05 #8

"Brian MacBride" <ma******@ix.netcom.com> wrote in message
news:bs************@ID-26770.news.uni-berlin.de...

"Andrew Skouloudis" <af********************@yahoo.com> wrote in message
news:7a********************************@4ax.com...

You didn't forget that you have this silly....

c = getchar ();

...here. Lose it...

Regards

Brian


I am not THAT stupid ...


I didn't mean to imply that you were. I often overlook the obvious at
times. Sometimes I can't see the forest for the trees. ;-)


See, I told you that we all overlook the obvious at times. As Michael Mellor
did, I
added a break to the loop in your void MACList::DeleteNode (const String
&mac) function, and then forgot to mention that to you. Sorry.

Regards

Brian
Jul 22 '05 #9
Hi,

Andrew Skouloudis <af********************@yahoo.com> wrote in message news:<o8********************************@4ax.com>. ..
Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include "GenericStringClass2.h"
#include <string.h>
Many of these headers are not necessary in your program. Also, you
should be using <iostream> instead of <iostream.h>.

#define DEFAULT 0
"const int DEFAULT = 0;" is better here.

(...)

MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";
if(this != NULL)
{

delete this;
}
else delete this;
As someone else has pointed out, you shouldn't do this. See the FAQ
for details:

http://www.parashift.com/c++-faq-lite/

}

MACListPart* MACListPart::GetNextPointer(void)
{
if(this==NULL)
{
cout << "You are pointing to nowhere , where do you
think you are going ??\n";
return NULL;
}
else
{
return this->next;
}
Here, IMHO, "assert(this != NULL)" would make more sense...

(...)
bool MACList::FindNode(const String& mac)
{
MACListPart *pMacListPart=head;
while(pMacListPart !=NULL)
{
if(pMacListPart->macAdr==mac)
{
return true;
}
}
return false;
}
You forgot to update pMacListPart.

(...)
void MACList::AddNode(const String& mac)
{
MACListPart *pMACListPart = new MACListPart;
pMACListPart->macAdr=mac;
pMACListPart->data=DEFAULT;
pMACListPart->next=NULL;

if(IsListEmpty() == true)
{
head=pMACListPart;
current=head;
}
else // (if IsListEmpty() == false )
{
current->next=pMACListPart;
current=pMACListPart;
If "current" is used only to help insertions at the end of the list,
its name is misleading; also, you may need to update it when you
delete a node.

}
// increasing the elements of the list
itsCount++;
}

(...)

The problem is when i am trying to delete a node .. The program hangs
after the command
delete currNode is executed ... The String class is declared in
another file and here is the
default destructor :


Hard to say anything without the complete String class, but you could
for example replace it with std::string (or, better yet, int) for
testing MACList separately.

HTH,
Wagner
Jul 22 '05 #10
On Mon, 29 Dec 2003 16:33:24 GMT, "Brian MacBride"
<ma******@ix.netcom.com> wrote:

"Brian MacBride" <ma******@ix.netcom.com> wrote in message
news:bs************@ID-26770.news.uni-berlin.de...

"Andrew Skouloudis" <af********************@yahoo.com> wrote in message
news:7a********************************@4ax.com...
>
> >
> >You didn't forget that you have this silly....
> >
> > c = getchar ();
> >
> >...here. Lose it...
> >
> >Regards
> >
> >Brian
> >
> >
>
> I am not THAT stupid ...


I didn't mean to imply that you were. I often overlook the obvious at
times. Sometimes I can't see the forest for the trees. ;-)


See, I told you that we all overlook the obvious at times. As Michael Mellor
did, I
added a break to the loop in your void MACList::DeleteNode (const String
&mac) function, and then forgot to mention that to you. Sorry.

Regards

Brian


I would like to thank you for your help ... I am new to C++
programming so I make many mistakes !!!
Jul 22 '05 #11
On 29 Dec 2003 09:39:08 -0800, wb****@yahoo.com (Wagner Bruna) wrote:
Hi,

Andrew Skouloudis <af********************@yahoo.com> wrote in message news:<o8********************************@4ax.com>. ..
Hello people and merry christmas. I am trying to create a simple
linked list and it seems i am
doing something wrong with the DeleteNode function ...

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include "GenericStringClass2.h"
#include <string.h>


Many of these headers are not necessary in your program. Also, you
should be using <iostream> instead of <iostream.h>.

#define DEFAULT 0


"const int DEFAULT = 0;" is better here.

(...)

MACListPart::~MACListPart(void)
{
cout << "Calling the default destructor for MACListPart ...
\n";
if(this != NULL)
{

delete this;
}
else delete this;


As someone else has pointed out, you shouldn't do this. See the FAQ
for details:

http://www.parashift.com/c++-faq-lite/

}

MACListPart* MACListPart::GetNextPointer(void)
{
if(this==NULL)
{
cout << "You are pointing to nowhere , where do you
think you are going ??\n";
return NULL;
}
else
{
return this->next;
}


Here, IMHO, "assert(this != NULL)" would make more sense...

(...)
bool MACList::FindNode(const String& mac)
{
MACListPart *pMacListPart=head;
while(pMacListPart !=NULL)
{
if(pMacListPart->macAdr==mac)
{
return true;
}
}
return false;
}


You forgot to update pMacListPart.

(...)
void MACList::AddNode(const String& mac)
{
MACListPart *pMACListPart = new MACListPart;
pMACListPart->macAdr=mac;
pMACListPart->data=DEFAULT;
pMACListPart->next=NULL;

if(IsListEmpty() == true)
{
head=pMACListPart;
current=head;
}
else // (if IsListEmpty() == false )
{
current->next=pMACListPart;
current=pMACListPart;


If "current" is used only to help insertions at the end of the list,
its name is misleading; also, you may need to update it when you
delete a node.

}
// increasing the elements of the list
itsCount++;
}

(...)

The problem is when i am trying to delete a node .. The program hangs
after the command
delete currNode is executed ... The String class is declared in
another file and here is the
default destructor :


Hard to say anything without the complete String class, but you could
for example replace it with std::string (or, better yet, int) for
testing MACList separately.

HTH,
Wagner

Thank you very much !! . Do you know whre I can download a zip file
containing the entire faq ??? (The administrator of the web site
http://www.parashift.com/c++-faq-lite/ has disabled that option !!)
Jul 22 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
10
by: Ben | last post by:
Hi, I am a newbie with C and am trying to get a simple linked list working for my program. The structure of each linked list stores the char *data and *next referencing to the next link. The...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
11
by: bofh1234 | last post by:
Hello, I am having a problem with linked lists. My program is based on a client server model. The client sends some packets of data to the server. The server reads those packets and is...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
12
by: kalyan | last post by:
Hi, I am using Linux + SysV Shared memory (sorry, but my question is all about offset + pointers and not about linux/IPC) and hence use offset's instead on pointers to store the linked list in...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.