This preview shows pages 1–3. Sign up to view the full content.
CS106X
Handout 25
Autumn 2010
October 27
th
, 2010
Section Handout
Problem 1: Removing Duplicates
Write a function
RemoveDuplicates
that given a linked list will remove and free the
second of all neighboring duplicates found in the list.
If the incoming list is
(5 5 22 37 89 89 15 15 22) the function will destructively modify the list to contain
(5 22 37 89 15 22).
Don't worry about duplicate sequences longer than 2 or duplicates
that aren't right next to each other in the list.
struct node {
int value;
node *next;
};
void RemoveDuplicates(node *list);
Problem 2: Braided Lists
Write a function called
Braid
that takes the leading address of a singly linked list, and
weaves the reverse of that list into the original.
struct node {
int value;
node *next;
};
Here are some examples:
list
list after call Braid(list)
1
4
2
1
2
4
4
2
1
3
3
3
1
3
6
10
15
1
15
3
10
6
6
10
3
15
1
You have this page and the next page to present your solution.
void Braid(node *list);
Problem 3: Intermingle and Cluster
Use the following data structure for both parts of this problem:
struct node {
int value;
node *next;
};
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
a.
Write the
Intermingle
function, which takes a linked list of integers and inserts a
new node in between every one of the originals, where the value in each new node is
the difference between the numbers on either side of it.
Here are some examples:
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 Cain,G

Click to edit the document details