-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.h
119 lines (104 loc) · 1.71 KB
/
LinkedList.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
using namespace std;
struct node
{
long long int info;
node *next;
};
class LinkedList
{
private:
node *L;
public:
LinkedList()
{
L = NULL;
};
int isempty();
void add(long long int item);
void print();
int traverse_and_check(long long int k);
void push(long long int k);
int pop();
};
int LinkedList::isempty()
{
int f=0;
if (L==NULL)
{
f=1;
}
return f;
}
void LinkedList::add(long long int item)
{
node *p;
p=new node;
p->info = item;
if(L==NULL)
{
p->next=NULL;
L=p;
}
else
{
p->next=L;
L=p;
}
}
void LinkedList::print()
{
if (isempty()==1)
{
return;
}
node *p;
p=L;
while(p!=NULL)
{
cout<<p->info<<endl;
p=p->next;
};
}
int LinkedList::traverse_and_check(long long int k)
{
long long int p;
long long int k1=k;
node *temp;
temp = L;
while(temp !=NULL)
{
p=temp->info;
while(k1%p == 0)
{
k1=k1/p;
};
temp=temp->next;
}
return k1;
}
void LinkedList::push(long long int item)
{
node *p;
p=new node;
if(L==NULL)
{
p->info=item;
p->next=NULL;
L=p;
}
else
{
p->info=item;
p->next=L;
L=p;
}
}
int LinkedList::pop()
{
long long int n;
n=L->info;
L=L->next;
return n;
}
//End of formation of LinkedList