Hi, I am a newbie to coding. I am trying to implement a graph in the following format.
User input:
v1 v2 edge_cost
1 3 10
1 2 20
2 3 40
3 1 30

I am storing the graph as an adjacency list, so that the output should be the following:
1 -- 3,2
2 -- 3
3 -- 1

It works fine for small inputs but whenever i pass more edges to it i get an error
"Unhandled exception at 0x010b1d2d in CppPractise.exe: 0xC0000005: Access violation reading location 0xfeeefeee."

Can anyone point out how i can correct this?

class graph
{
private:
	struct listNode
	{
		int v;
		int e;
		listNode *next;
		listNode *down;
	};

	listNode *head;

public:
	graph()
	{
		head = NULL;
	}

	void inpUsrGraph();
	void inpGraph(int ,int , int );
	void dispGraph();
};

void graph::inpUsrGraph()
{
	int fn_exit=0;
	int v1,v2,e;
	string do_exit;
	cout<<"Enter the graph inputs as V1 V2 E (* to exit)\n";
	do{
		cin>>do_exit;
		if(do_exit.compare("*")==0)
			fn_exit=1;
		else
			{
				v1=atoi(do_exit.c_str());
				cin>>do_exit;
				if(do_exit.compare("*")==0)
					fn_exit=1;
				else
				{
					v2=atoi(do_exit.c_str());
					cin>>do_exit;
					if(do_exit.compare("*")==0)
						fn_exit=1;
					else
						e=atoi(do_exit.c_str());
				}
			}

		if(!fn_exit)
			inpGraph(v1,v2,e);
	}while(!fn_exit);
}

void graph::inpGraph(int v1,int v2,int cost)
{
	listNode *newNode = NULL;
	listNode *downNode = NULL;
	listNode *nodePtr = NULL;
	listNode *downPtr = NULL;

	newNode = new listNode;
	newNode->v=v1;
	newNode->e=-1;
	newNode->next=NULL;
	newNode->down=NULL;

	downNode = new listNode;
	downNode->v=v2;
	downNode->e=cost;
	downNode->down=NULL;
	downNode->next=NULL;

	if(!head)
	{
		head=newNode;
		head->down=downNode;
	}
	else
	{
		nodePtr = head;

		do
		{
			if(newNode->v==nodePtr->v)
			{
				delete newNode;
				newNode=nodePtr;
				downPtr=newNode->down;
				do
				{
					if(downPtr->v==downNode->v)
						{
						delete downNode;
						break;
						}
					else if(downPtr->down==NULL)
						{
						downPtr->down=downNode;
						downPtr=downNode;
						}
					downPtr=downPtr->down;
				}while(downPtr);
			}
			else if(nodePtr->next==NULL)
			{
				nodePtr->next=newNode;
				newNode->down=downNode;
				nodePtr=newNode;
			}
			
			nodePtr=nodePtr->next;

		}while(nodePtr);
	}
}

void graph::dispGraph()
{
	listNode *nextPtr;
	listNode *nextDown;

	nextPtr=head;

	while(nextPtr)
	{
		cout<<nextPtr->v<<"  --  ";
		nextDown=nextPtr->down;
		while(nextDown)
		{
			cout<<" "<<nextDown->v;
			nextDown=nextDown->down;
		}
		cout<<endl;
		nextPtr=nextPtr->next;
	}
}

Recommended Answers

All 3 Replies

I am getting this error in the inpGraph function while inserting a new edge. I am using VC++ 2008 express ed. Also there seems to be an error with the following modules (I dont even know how they are being called)
ntdll.dll
kernel32.dll
KernelBase.dll

for each of the above it says "Cannot find or update PDB file."

0xFEEEFEEE is used by Microsoft's HeapFree() to mark freed heap memory. This would seem to indicate that you are freeing memory (for example, as part of delete), and then trying to use it anyway.

I understand that you can run in debug mode; if you run it in debug mode, it may well simply tell you which line of your code is causing the problem.

0xFEEEFEEE is used by Microsoft's HeapFree() to mark freed heap memory. This would seem to indicate that you are freeing memory (for example, as part of delete), and then trying to use it anyway.

I understand that you can run in debug mode; if you run it in debug mode, it may well simply tell you which line of your code is causing the problem.

Thanks.. thats exactly what it was

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.