Hi all, I have a c++ program i'm working on focusing on pointers in a circular linked list.
I need to have the user specify the position of the "dog" in the line (the program is a mock dog show). Then a function checks for the specified position and returns a pointer to it. however, I am stuck on where to go after I return the pointer.
struct Nodetype
{
int id;
char name[20];
char breed[50];
int position;
Nodeptr Left, Right;
int numnodes;
};
void Reposition(Nodeptr Head)
{
int pos;
bool Empty(Nodeptr List);
do{
cout<<"Enter the position of the dog you wish to move: ";
cin>>pos;
cin.ignore();
Nodeptr Search2(Nodeptr List, int pos);
}while(
//This is where I want to access p but don't know how.
//I need to reposition it so i need to access its Right and Left
)
return;
}
Nodeptr Search2(Nodeptr Head, int pos)
{
int found = 0;
Nodeptr p;
bool Empty(Nodeptr List);
if (Empty(Head))
return NULL;
else
{
p = Head->Right;
do
{
if (pos == p->position)
found = 1;
else
p = p->Right;
}while (!found &&(p != Head));
if (p != Head)
return p;
else
return NULL;
}
}
I have tried to use the returned pointer, p, in the reposition() function. Maybe I don't know what exactly i am returning????
Ideas or any help would be awesome thanks!
eric