ceye1992 于 2016.04.28 18:02 提问

#include

struct entry
{
int date;
struct entry *next;
};

void insertEntry (struct entry beInsert, struct entry insert)
{

``````beInsert.next = insert.next;
insert.next = &beInsert;
``````

}

int main(void)
{
struct entry n1, n2, n3, n4;

``````struct entry *listStar = &n1;  //开头

n1.date = 10;
n1.next= &n2;

n2.date = 20;
n2.next = &n3;

n3.date = 30;
n3.next = (struct entry *)0;  //结尾

n4.date = 50;

insertEntry(n4, n2);
``````

// n4.next = n2.next; 这两行是函数运行的模式，不用函数直接运行能得到结果
//n2.next = &n4;

``````while(listStar != (struct entry *)0)
{
printf("%i\n", listStar->date);
listStar = listStar->next;
}

return 0;
``````

}

``````
``````

1个回答

asd001110   2016.05.03 00:07

struct entry
{
int date;
struct entry *next;
};
void insertEntry (struct entry *beInsert, struct entry *insert)
{
beInsert->next = insert->next;
insert->next = beInsert;
}
int main(void)
{
struct entry n1, n2, n3, n4;
struct entry *listStar = &n1; //开头

n1.date = 10;
n1.next= &n2;

n2.date = 20;
n2.next = &n3;

n3.date = 30;
n3.next = (struct entry *)0; //结尾

n4.date = 50;

insertEntry(&n4, &n2);
// n4.next = n2.next; 这两行是函数运行的模式，不用函数直接运行能得到结果
//n2.next = &n4;
while(listStar != (struct entry *)0)
{
printf("%i\n", listStar->date);
listStar = listStar->next;
}

``````system("pause");
``````

return 0;
}