Updated the add last element inti linkedlist
This commit is contained in:
parent
cdb08a328e
commit
b9356d3bc3
BIN
tests/linkedlist
BIN
tests/linkedlist
Binary file not shown.
@ -25,7 +25,7 @@ int main(void)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
// show menu
|
// show menu
|
||||||
display_menu();
|
display_menu();
|
||||||
|
|
||||||
@ -122,11 +122,13 @@ void add_last(int element)
|
|||||||
{
|
{
|
||||||
head = node;
|
head = node;
|
||||||
head->next = NULL;
|
head->next = NULL;
|
||||||
|
|
||||||
|
printf("Element %d has been add into first/last!\n", element);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// store current as tempo
|
// store current as tempo
|
||||||
temp = node;
|
temp = head;
|
||||||
|
|
||||||
while (temp->next != NULL)
|
while (temp->next != NULL)
|
||||||
{
|
{
|
||||||
@ -134,7 +136,8 @@ void add_last(int element)
|
|||||||
}
|
}
|
||||||
|
|
||||||
temp->next = node;
|
temp->next = node;
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
|
head = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void traverse()
|
void traverse()
|
||||||
|
Loading…
Reference in New Issue
Block a user