Dsal Assignment 2
Dsal Assignment 2
ASSIGNMENT NO 2
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node *next;
Node(int n)
{
data = n;
next = nullptr;
}
};
class LinkedList
{
private:
Node *head;
public:
LinkedList()
{
head = nullptr;
}
void append(int n)
{
Node *newNode = new Node(n);
if (head == nullptr)
{
head = newNode;
return;
}
void display()
{
Node *temp = head;
while (temp != nullptr)
{
cout << temp->data <<" ";
temp = temp->next;
}
cout << "null" << endl;
}
};
int main()
{
LinkedList l1,l2;
l1.append(1);
l1.append(3);
l1.append(4);
l2.append(1);
l2.append(2);
l2.append(4);
return 0;
}
Output