Question: Write a function that groups nodes with the same value in a linked list. The code you will write will rearrange all duplicate values in

Write a function that groups nodes with the same value in a linked list.
The code you will write will rearrange all duplicate values
in the list sequentially side by side.
should be regulated. For example, let's say the number
"
3
"
repeats four times in the list. In this case first
Other repeating numbers
"
3
"
should appear right next to the number
"
3
"
encountered. So the list is first
will be in the same order as the situation.
The function you will write will have
2
parameters: A Node pointer that represents the head of the linked list.
max
_
repeats for reference and maximum number to combine. Other with the same value
values
should be deleted.
For example, let's say a linked list looks like this:
{
1
,
3
,
4
,
5
,
2
,
3
,
5
,
6
,
1
,
4
,
5
,
6
,
6
,
7
,
4
,
5
}
The grouping function we wrote, for example: after calling group
(
head
,
1
0
)
should look like this:
{
1
,
1
,
3
,
3
,
4
,
4
,
4
,
5
,
5
,
5
,
5
,
2
,
6
,
6
,
6
,
7
}
Since the value of
1
0
we gave to the max
_
repeat parameter above was too high, none of its elements were deleted.
If we called the function as group
(
head
,
2
)
,
the final situation would be as follows:
{
1
,
1
,
3
,
3
,
4
,
4
,
5
,
5
,
2
,
6
,
6
,
7
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!