Dsa Lab Quiz 3
Dsa Lab Quiz 3
31184
DSA
LAB QUIZ 3
Code:
#include <iostream>
using namespace std;
struct Node
{
int data;
Node * next;
};
void append(Node ** head_ref, int new_data) //here Head mean Header which is to point the first node
{
//1. allocate node
Node * new_node = new Node ();
//Used in step 5
Node * last = *head_ref;
//2. assign data
new_node->data = new_data;
//3. This new node gonna be the last node so make next of it as NULL
new_node->next = NULL;
//4. If the Linked List is empty,then make the new code as head
if(*head_ref == NULL)
{
*head_ref = new_node;
return;
}
else
{
//5. Else, traverse to the last node
Node *last_node = *head_ref;
//last node's next address will be NULL.
while (last_node->next != NULL)
{
}
void printlist(Node *node)
{
while(node != NULL)
{
cout<< " "<<node->data;
node= node->next;
}
}
int main()
{
cout << "Tanzeel Hussain" << endl;
cout << "31184\n" << endl;
append(&head,789);
push(&head,31184);
push(&head, 456);
push(&head, 123);
return 0;
}
OUTPUT