Professional Documents
Culture Documents
addNode_end(head,50);
display(head);
cout << endl;
return 0;
}
#include <iostream>
using namespace std;
typedef struct LLSI
{
int info;
LLSI *next;
}NODE;
void initNODE(NODE *head, int n)
{
head->info = n;
head->next =NULL;
}
void addNODE(NODE *head, int n)
{
NODE *new_node = new NODE;
new_node->info = n;
new_node->next = NULL;
NODE *temp = head;
while (temp != NULL)
{
if (temp->next == NULL)
{
temp->next = new_node;
return;
}
temp = temp->next;
}
}
void display(NODE *head)
{
NODE *temp;
temp = head;
cout << endl;
while (temp)
{
cout << " " << temp->info << " ->";
temp = temp->next;
}
cout << " NULL";
}
int main()
{
NODE *head;
head = new NODE;
initNODE(head,10);
display(head);
addNODE(head,20);
display(head);
addNODE(head,30);
display(head);
addNODE(head,40);
display(head);
addNODE(head,50);
display(head);
cout << endl;
return 0;
}