我认为它应该可以工作,我尝试做的是捕获一个值并将其打印在屏幕上,但我收到以下错误。
C:\Users\luis\Documents\c++\estructura de datos\ejemplo_lista.cpp 在函数 'void mostrar()' 中:80 13 C:\Users\luis\Documents\c++\estructura de datos\ejemplo_lista.cpp [错误] 'list' 未在此范围内声明 80 20 C:\Users\luis\Documents\c++\estructura de datos\ejemlo_lista.cpp [错误] 'value' 未在此范围内声明
-------开始主---------------------
int main(){
menu();
show();
getch();
}
------结束MAIN------------------------------------
//Function Menu
void menu()
{
NODE = NULL;
int choice;
int value;
while(choice!= 2){
printf("********** MENU **********\n");
printf ("1. Login data \n");
printf ("2. exit \n");
printf("**************************\n");
scanf ("%i",&choice);
switch (choice){
case 1:
printf("Please enter a value \n");
scanf("%i",&value);
add (list, value);
break;
case 2:
break;
}
system("pause");
}
}
输入功能
void add (NODE &list,int value)
{
NODE aux_list;
aux_list =(data_structure*) malloc (sizeof (data_structure));
aux_list->data = value;
aux_list->next = list;
list = aux_list;
}
void show()
{
NODE other_list;
add(list, value);
other_list = list;
/ / Display the elements of the list
while(other_list != NULL)
{
printf("%i \n",other_list->data);
other_list = other_list->next;
}
}
- - - - - - - - - - - 编辑 - - - - - - - - - - - - -
ready to solve it this way
void mostrar(NODO lista,int valor)
{
lista=NULL;