-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModular_node.cpp
More file actions
74 lines (74 loc) · 1.42 KB
/
Modular_node.cpp
File metadata and controls
74 lines (74 loc) · 1.42 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
};
void show(node *head)
{
node *current = head;
cout<<"The list is: ";
while(current!=NULL)
{
cout<<current->data<<" ";
current = current->next;
}
cout<<endl;
}
void insert(node **head , int n)
{
node *link = new node;
link->data = n;
link->next = NULL;
if(*head==NULL)
*head = link;
else
{
node *current = *head;
while(current->next!=NULL)
current = current->next;
current->next = link;
}
show(*head);
}
int length(node* head)
{
int count=0;
node *current = head;
if(!current)
return 0;
while(current!=NULL)
{
count++;
current = current->next;
}
return count;
}
void modularNode(node *head, int k)
{
int len = length(head);
int point = (len/k)*k;
node *current = head;
while(current!=NULL && point-1)
{
current = current->next;
point--;
}
cout<<"The modular node is "<<current->data;
}
int main()
{
node *head = NULL;
cout<<"Enter the element to be entered in list(0 to end)"<<endl;
int n;
while(cin>>n)
if(n)
insert(&head,n);
else
break;
cout<<"Enter the value of k whose n%k=0"<<endl;
int k;
cin>>k;
modularNode(head,k);
}