25-Section-Handout

25-Section-Handout - CS106X Autumn 2010 Handout 25 October...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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; };
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 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:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

25-Section-Handout - CS106X Autumn 2010 Handout 25 October...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online