-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcircularll.cpp
More file actions
58 lines (56 loc) · 1.01 KB
/
circularll.cpp
File metadata and controls
58 lines (56 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
using namespace std;
// Create a class node for the circular linked list
class node
{
public:
int data;
node*next;
node(int data)
{
this->data = data; // Refering to data
//Here the tail pointer would point to head of the node instead of the NULL
}
};
// A function which is used to print the list
void printlist(node *head)
{
node *temp = head;
while(temp->next != head)
{
cout<<temp->data<<"->";
temp = temp->next;
}
cout<<temp->data<<endl;
cout<<"ENDL";
}
//A function used to push the node in the linked list
void push(node *&head , int data)
{
node *ptr1 = new node(data);
node *temp = head;
ptr1->next = head;
if(head != NULL)
{
while(temp->next!=head)
{
temp = temp->next;
}
temp->next = ptr1;
}
else
{
ptr1->next = ptr1;
}
head = ptr1;
}
int main(int argc, char const *argv[])
{
node *head = NULL;
push(head,10);
push(head,20);
push(head,30);
push(head,40);
printlist(head);
return 0;
}