void addToEnd()
{
newnode = (struct node*)malloc(sizeof(struct node));
printf ("Enter the customer name :");
scanf ("%s", newnode->cName);
printf ("\nEnter customer number :");
scanf ("%d", &newnode->cNumber);
printf ("\nEnter transaction description :");
scanf ("%s", newnode->tDescrip);
newnode->next = NULL;
if(list==NULL)
list = newnode;
else if (list != NULL && newnode < list)
{
newnode->next = list;
list = newnode;
}
else
{
temp = list;
while (temp != NULL)
{
if (newnode > temp)
{
prev = temp;
temp = temp->next;
}
}
newnode->next = prev->next;
prev->next = newnode;
}
}
我想這代碼,但那朵代碼只需添加到開始而不是結束,我怎麼想的節點添加到盡頭?怎麼節點添加到末尾(單鏈表)
你需要找到結束。 – 2012-01-28 06:22:13