0% found this document useful (0 votes)
3 views1 page

MiniProject

The document outlines a mini project for implementing various functions using singly linked lists in data structures and algorithms. It includes tasks such as splitting a list into two halves, moving nodes between lists, alternating splits, shuffle merging two lists, and reversing a list iteratively and recursively. Each function has specific requirements and examples to guide implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

MiniProject

The document outlines a mini project for implementing various functions using singly linked lists in data structures and algorithms. It includes tasks such as splitting a list into two halves, moving nodes between lists, alternating splits, shuffle merging two lists, and reversing a list iteratively and recursively. Each function has specific requirements and examples to guide implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Mini Project for 21CSC201J Data Structures and Algorithms

Implement the given functions using linked lists. All of the linked list code in the
solution should use the "classic" singly linked list structure: A single head pointer
points to the first node in the list. Each node contains a single .next pointer to the next
node. The .next pointer of the last node is NULL. The empty list is represented by a
NULL head pointer.

1) Split(InList, OutList1, OutList2)


Given a list, split it into two sublists — one for the front half, and one for the back
half. If the number of elements is odd, the extra element should go in the front list. So
Split() on the list {2, 3, 5, 7, 11} should yield the two lists {2, 3, 5} and {7, 11}.
Getting this right for all the cases is harder than it looks. You should check your
solution against a few cases (length = 2, length = 3, length=4) to make sure that the
list gets split correctly near the short-list boundary conditions. If it works right for
length=4, it probably works right for length=1000. You will probably need special
case code to deal with the (length <2) cases.

2) MoveNode(InList1, InList2)
Given two lists, the function removes the front node from the second list and pushes
it onto the front of the first.

3) AlternatingSplit(InList, OutList1, OutList2)


Write a function that takes one list and divides up its nodes to make two smaller lists.
The sublists should be made from alternating elements in the original list. So if the
original list is {a, b, a, b, a}, then one sublist should be {a, a, a} and the other should
be {b, b}.

4) ShuffleMerge(InList1, InList2, OutList)


Given two lists, merge their nodes together to make one list, taking nodes alternately
between the two lists. So ShuffleMerge() with {1, 2, 3} and {7, 13, 1} should yield
{1, 7, 2, 13, 3, 1}. If either list runs out, all the nodes should be taken from the other
list.

5) Reverse(InList, OutList)
Write an iterative function that reverses a list by rearranging all the .next pointers and
the head pointer. Ideally, Reverse() should only need to make one pass of the list. Try
writing a recursive solution for the same problem.

You might also like