-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask1.cpp
95 lines (86 loc) · 1.61 KB
/
task1.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Will be implementing Singly Circular Linked List as Doubly haven't discussed yet in lectures
#include <iostream>
using namespace std;
class Node
{
int Data;
Node *Next;
public:
// default constructor
Node();
// setters
void setData(int);
void setNext(Node *);
// getters
int getData();
Node *getNext();
};
// Function Implementattion for class Node
// default constructor
Node ::Node()
{
Data = 0;
Next = NULL;
}
// setters
void Node ::setData(int x)
{
Data = x;
}
void Node ::setNext(Node *next)
{
Next = next;
}
// getters
int Node ::getData()
{
return Data;
}
Node *Node ::getNext()
{
return Next;
}
class CircularLinkedList
{
// private:
Node *Head;
public:
// default constructor
CircularLinkedList();
// parameterized constructor
CircularLinkedList(int);
};
// Function Implementattion for class CircularLinkedList
// default constructor
CircularLinkedList ::CircularLinkedList()
{
Head = NULL;
}
// parameterized constructor
CircularLinkedList ::CircularLinkedList(int x)
{
Head = NULL;
Node *newnode = new Node;
newnode->setData(x);
// for making circular linked list
if (Head == NULL)
{
Head = newnode;
newnode->setNext(Head);
}
else
{
Node *temp = Head;
while (temp->getNext() != NULL)
{
temp = temp->getNext();
}
temp->setNext(newnode);
temp->setNext(Head);
}
}
int main()
{
CircularLinkedList l1(4);
return 0;
}