void menu()
{
int userinput;
static value *head = NULL;
static value *tail = NULL;
cout << "1 - Insert value" << endl;
cout << "2 - Print list" << endl;
cout << "3 - Delete value" << endl;
cout << "4 - Quit" << endl;
cout << "5 - Error checking" << endl << endl;
cout << "Your Choice : ";
cin >> userinput;
if(userinput == 1)
{
insertvalue(head, tail);
}
}
void insertvalue(value *head, value *tail)
{
int newv;
value *newvalue = new value;
system("cls");
cout << "Insert a value for linked list: ";
cin >> newv;
newvalue->v = newv;
newvalue->link = NULL;
if(head == NULL)
{
head = tail = newvalue;
}
else
{
tail->link = newvalue;
tail = newvalue;
}
cout << endl << "Returning to menu" << endl;
cout << head->v << endl;
system("pause");
system("cls");
menu();
}
It seems like my head is always reset back to NULL when i called back menu() in insertvalue() despite the static there.
so is it possible to let my head be the same value throughout the whole looping?