Skip to content

Commit

Permalink
Merge pull request #3 from iampavangandhi/master
Browse files Browse the repository at this point in the history
Added a LinkedList File
  • Loading branch information
jaspreetkaur96 committed Oct 4, 2019
2 parents 73259d5 + 92a1f8e commit 4803505
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions iampavangandhi - LinkedLIST.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
using namespace std;

struct node
{
int inf;
node *next;
};

class Linked_list
{
private:
node *head,*tail;
public:
Linked_list()
{
head = NULL;
tail = NULL;
}

void add_node(int n)
{
node *tmp = new node;
tmp->inf = n;
tmp->next = NULL;

if(head == NULL)
{
head = tmp;
tail = tmp;
}
else
{
tail->next = tmp;
tail = tail->next;
}
}

void display()
{
node *tmp;
tmp = head;
while(tmp!=NULL)
{
cout<<" DATA: "<<tmp->inf<<" ADDRESS: ";
cout<<tmp->next<<endl;
tmp = tmp->next;
}
}
};

int main()
{
Linked_list a;
a.add_node(1);
a.add_node(2);
a.add_node(3);
a.add_node(4);
a.add_node(5);
a.display();
return 0;
}

0 comments on commit 4803505

Please sign in to comment.