PDA

View Full Version : مبتدی: سوال در مورد لیست پیوندی



aali361
دوشنبه 26 خرداد 1393, 02:40 صبح
سلام . در این کد چرا first=null انجام نمیشه ؟

#include <iostream>#include <conio.h>
using namespace std;
struct node{
public:
int id;
node *first = NULL;
node *last = NULL;
node *next;
node *priv;
};
void main()
{
int i;
node *first=NULL;
node* insert(node *,node *);
for (;;)
{
cin >> i;
if (i == 1)
{
node *temp;
temp = new node;
cin >> i;
temp->id = i;
first = NULL;
if (first = NULL)
cout << "null";
else
cout << "no null";
first = insert(temp,first);


}
if (i == 2)
{
for (first; first != NULL; first = first->next)
cout << first->id;
}
}
}
node* insert(node *temp,node *first)
{
node *last;
if (first == NULL)
{
cout << "1";
first = temp;
first->next = NULL;
first->priv = NULL;
last = first;
return first;
}
else
{
temp->next = first;
temp->priv = NULL;
first = temp;
return first;
}
}

aali361
دوشنبه 26 خرداد 1393, 02:42 صبح
من یه بار تو خط چهارده و یه باره توخط 25 اومدم فرست رو نال کردم اما نال نمیشه ؟

aali361
دوشنبه 26 خرداد 1393, 19:12 عصر
کسی نظری نداره ؟