hi every1 i have this code which is delete a node in the graph
but there is 5 errors and 1 warning I need u to help me with this errors
#include<iostream>
using namespace std;
template<class TYPE>
struct Vertex;
template<class TYPE>
struct Arc;
template<class TYPE>
struct Vertex
{
Vertex<TYPE> *pNextVertex;
TYPE data;
int inDegree;
int outDegree;
short processed;
Arc<TYPE> *pArc;
};//VERTEX
template<class TYPE>
struct Arc
{
Vertex<TYPE> *destination;
Arc<TYPE> *pNextArc;
};//ARC
template<class TYPE, class KTYPE>
class Graph
{
private:
int count;
Vertex<TYPE> *first;
public:
Graph (void);
~Graph (void);
int insertVertex (TYPE dataIn);
int deleteVertex (KTYPE dltKey);
int insertArc (KTYPE fromKey,KTYPE toKey);
int deleteArc (KTYPE fromKey,KTYPE toKey );
};
/* =============== insertVertex ==============
This function insert new data into the graph.
Pre dataIn contain data to be inserted
Post data have been inserted or memory overflow
Return 1 if succeful; -1 if memory overflow
*/
template <class TYPE, class KTYPE>
int Graph<TYPE,KTYPE>::insertVertex (TYPE dataIn)
{
Vertex<TYPE> *newPtr;
Vertex<TYPE> *locPtr;
Vertex<TYPE> *predPtr;
newPtr=new Vertex<TYPE>;
if(newPtr)
{
newptr->pNextVertex=NULL;
newptr->data=dataIn;
newptr->inDegree =0;
newptr->outDegree =0;
newptr->processed =0;
newptr->pArc=NULL;
count++;
}
else
return -1;
locPtr=first;
if(!locPtr)
first=newptr;
else
{
predPtr=NULL;
while(locPtr&&data.key>(locPtr->data).key)
{
predPtr=locPtr;
locPtr=locPtr->pNextVertex;
}
if(!predPtr)
first=newptr;
else
predPtr->pNextVertex=newptr;
newptr->pNextVertex=locptr;
}
return 1;
}
/* =============== insertArc ==============
This function add an arc vertex between to vertices.
Pre fromKey is key of start vertex.
toKey is key of destination vertex
Post arc have been added to adjency list
Return 1 if succeful; -1 if memory overflow;
-2 if fromKey not found ;-3 if toKey not found
*/
template <class TYPE, class KTYPE>
int Graph<TYPE,KTYPE>::insertArc (KTYPE fromKey , KTYPE toKey)
{
Arc<TYPE> *newPtr;
Arc<TYPE> *arcPredPtr;
Arc<TYPE> *arcWalkPtr;
Vertex<TYPE> *vertFromPtr;
Vertex<TYPE> *vertToPtr;
newptr=new Arc<TYPE>;
if(!newPtr)
return -1;
vertFromPtr=first;
while(vertFromPtr&&fromKey>(vertFromPtr->data).key)
vertFromPtr=vertFromPtr->pNextVertex;
if(!vertFromPtr||fromKey!=(vertFromPtr->data).key)
return -2;
vertToPtr=first;
while(vertToPtr&&toKey>(vertToPtr->data).key)
vertToPtr=vertToPtr->pNextVertex;
if(!vertToPtr||toKey!=(vertToPtr->data).key)
return -3;
++vertFromPtr->outDegree;
++vertToPtr->inDegree;
newptr->destination=vertToPtr;
if(!vertFromPtr->pArc)
{
vertFromPtr->pArc=newptr;
newptr->pNextArc=NULL;
return 1;
}
arcPredPtr=NULL;
arcWalkPtr=vertFromPtr->pArc;
while(arcWalkPtr&&toKey>=(arcWalkPtr->destination->data.key))
{
arcPredPtr=arcWalkPtr;
arcWalkPtr=arcWalkPtr->pNextPtr;
}
if(!arcPredPtr)
vertFromPtr->pArc=newptr;
else
arcPredPtr->pNextArc= newptr;
newptr->pNextArc=arcWalkPtr;
return 1;
}
/* =============== deleteARC ==============
This function delete vertex only if its degree 0.
Pre dltKey is the Key
Post data have been inserted or memory overflow
Return 1 if succeful; -1 if memory overflow
*/
template <class TYPE, class KTYPE>
int Graph<TYPE,KTYPE>::deleteArc (KTYPE fromKey,KTYPE toKey)
{
Vertex<TYPE> *fromVertexPtr;
Vertex<TYPE> *toVertexPtr;
Arc<TYPE> *arcWalkPtr;
Arc<TYPE> *preArcPtr;
if(!first)
return -2;
fromVertexPtr=first;
while(fromVertexPtr&&fromKey>(fromVertexPtr->data).key)
fromVertexPtr=fromVertexPtr->pNextVertex;
if(!fromVertexPtr||fromKey!=(fromVertexPtr->data).key)
if(!fromVertexPtr->pArc)
return -3;
preArcPtr=NULL;
arcWalkPtr=fromVertexPtr->pArc
while(arcWalkPtr&&toKey>(arcWalkPtr->destination->data).key)
{
preArcPtr=arcWalkPtr;
arcWalkPtr=arcWalkPtr->pNextArc;
}
if(!arcWalkPtr||toKey!=(arcWalkPtr->destination->data.key))
return -3;
toVertexPtr=arcWalkPtr->destination;
--fromVertexPtr->outDegree;
--toVertexPtr->inDegree;
if(!preArcPtr)
fromVertexPtr->pArc=arcWalkPtr->pNextArc;
else
preArcPtr->pNextArc=arcWalkPtr->pNextArc;
delete arcWalkPtr;
return 1;
}
/* =============== deleteVertex ============== */
template<class TYPE,class KTYPE>
int Graph<TYPE,KTYPE>::deleteVertex(KTYPE dltKey)
{
Vertex<Type> *predPtr;
Vertex<Type> *walkPtr;
if(!first)
return -2;
predPtr=NULL;
walkPtr=first;
while(walkPtr&&dltKey>(walkPtr->data).key)
{
predPtr=walkPtr;
walkPtr=walkPtr->pNextVertex;
}
if(!walkPtr||dltKey!=(walkPtr->data.key))
return -2;
if(!predPtr)
first = walkPtr->pNextVertex;
else
predPtr->pNextVertex=walkPtr->pNextVertex;
count--;
deleteArc(key);
delete walkPtr;
return 1;
}
/*==============VERTEX Struct==============*/
struct VERTEX
{
int data_v;
};
/*==============ARC Struct==============*/
struct ARC
{
int data_a;
};
/*============insert_v==========================*/
void insert_v(Graph<VERTEX,ARC>&graph)
{
bool vert;
VERTEX ver;
cout<<"Enter the data/n";
cin>>ver.data_v;
vert=graph.insertVertex(ver);
}
/*============insert_a==========================*/
void insert_a(Graph<VERTEX,ARC>&graph)
{
bool vert;
ARC arc;
VERTEX ver;
cout<<"Enter the vertex/n";
cin>>ver.data_v;
cout<<"Enter the data/n";
cin>>arc.data_a;
vert=graph.insertArc(arc);
}
/*============delete_v==========================*/
void delete_v(Graph<VERTEX,ARC>&graph)
{
VERTEX ver;
bool vert;
cout<<"Enter the data/n";
cin>>ver.data_v;
vert=graph.deleteVertex(ver);
}
/*============main==========================*/
int main()
{
Graph<VERTEX,ARC>&graph;
int choice;
bool valid;
//int data_v;
//int data_a;
cout<<"***************MENU**********************"<<endl;
cout << "1. Insert vertex.\n"
<<"2. Insert arc.\n"
<<"3. delete node.\n"
<<"4. Exit\n";
cout<<"ENTER YOUR CHOICE"<<endl;
do{
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter/n";
cin>>data_v;
insert_v(data_v);
break;
case 2:
cout<<"Enter/n";
cin>>data_a;
insert_a(data_a);
break;
case 3:
cout<<"Enter/n";
cin>>data_v;
delete_v(data_v);
break;
case 4:
exit(1);
break;
}//switch
}while(choice!=4);
return 0;
}
The error:
delete.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\delete_v\delete.cpp(657) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
C:\Program Files\Microsoft Visual Studio\MyProjects\delete_v\delete.cpp(670) : error C2660: 'insertArc' : function does not take 1 parameters
C:\Program Files\Microsoft Visual Studio\MyProjects\delete_v\delete.cpp(681) : error C2664: 'deleteVertex' : cannot convert parameter 1 from 'struct VERTEX' to 'struct ARC'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\delete_v\delete.cpp(687) : error C2530: 'graph' : references must be initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\delete_v\delete.cpp(708) : error C2065: 'data_v' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\delete_v\delete.cpp(713) : error C2065: 'data_a' : undeclared identifier
Error executing cl.exe.