راهنمايي فوري: >> ليست پيوندي
سلام دوستان
من تازه ليست پيوندي رو شروع كردم و يك برنامه نوشتم كه يه جاهاييش اشكال داره اما سر در نميارم!
لطفا راهنمايي كنيد.
کد:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
struct node
{
int data;
node *next;
};
node *p, *temp, *first;
int i = 0;
int a;
void remove();
void survey();
void eventi();
void input();
int menu();
void main()
{
while(1)
{
clrscr();
switch(menu())
{
case 1:
input();
break;
case 2:
eventi();
break;
case 3:
survey();
break;
case 4:
remove();
break;
case 5:
exit(1);
}
}
}
int menu()
{
int x;
cout<<"1) Input 10 num.\n";
cout<<"2) Event Ingredient.\n";
cout<<"3) List Survey.\n";
cout<<"4) Remove All List.\n";
cout<<"5) Exit.\n\n\n\n";
cout<<"Choice 1-5:";
cin>>x;
return x;
}
void input()
{
p = first = new node;
temp = new node;
temp -> next = NULL;
while( i < 10)
{
cout << "Number "<<i<<":";
cin >> a;
p -> data = a;
if ( first == NULL)
{
first = p;
temp = first;
}
else
{
temp = new node;
p -> next = temp;
p = temp;
}
i++;
}
}
void eventi()
{
p=first;
while (i < 10)
{
if ( p -> data % 2 == 0 )
{
cout << p -> data << " ";
p = p -> next;
}
i++;
}
getch();
}
void survey()
{
p=first;
while ( i < 10)
{
cout << "Show List:";
cout << p -> data << " ";
p = p -> next;
i++;
}
getch();
}
void remove()
{
while(p)
{
p=first;
first=first->next;
p -> next = NULL;
delete p;
}
cout<<"Finish.";
}