1 INTRODUCTION

A ChunkList is like a regular linked list, except each node contains a little fixed size array of elements instead of just a single element. Each node also contains its own "size" int to know how full it is.

The ChunkList will have the following features...

  • The ChunkList object contains a head pointer to the first chunk, a tail pointer to the last chunk, and an int to track the logical size of the whole collection. When the size of the list is 0, the head and tail pointers are null. see image.
  • Each chunk contains a fixed size ItemT [] array, an int to track how full the chunk is, and a next pointer. There should be a constant ARRAY_SIZE = 8 that defines the fixed size of the array of each chunk. Elements should be added to the array starting at its 0 index. Elements in each little array should be kept in a contiguous block starting at 0 (this will require shifting elements around in the little array at times). You may want to test ARRAY_SIZE set to smaller values, but turn it in with ARRAY_SIZE set to 8.
  • The empty collection should be implemented as null head and tail pointers. Only allocate chunks when actually needed.
  • ChunkList should implement the following methods:
    • Append(ItemT elem)
    • GetLength() -> (refers to the total number of elements, not the number of chunk nodes)
    • GetIndex(int i) -> (gets the item at index i)
    • Search(ItemT elem)
    • Print
    • Remove(ItemT elem) -> (removes first instance of elem)
    • IsEmpty
  • The Append operation should add new elements at the end of the overall collection - i.e. new elements should go into the tail chunk. If the tail chunk is full, a new chunk should be added and become the new tail. We are not going to trouble ourselves shifting things around to use empty space in chunks in the middle of the list.
  • The Remove operation should look through each chunk array until the target element is found. Since the ChunkList can potentially have duplicates of the same elements, Remove should just delete the first found instance of the element. If the chunk node is empty after removing the element, then the entire chunk should be removed from the link list.
  • Do not use a dummy node because (a) it does not help the code much, and (b) dummy nodes are lame.
  • Keep a single "len" variable for the whole list that stores the total number of client data elements stored in the list. Similarly, keep a separate "len" variable in each chunk to know how full it is.
  • Search should return a copy of the element if found. Otherwise it should return null.

2 TEST DRIVER

You should have a test driver similar to the list driver demonstrated in class. Much of this driver can be reused for testing your implementation of ChunkList. In particular, it should support the following commands:

  • Append
  • GetLength
  • GetIndex
  • Search
  • Print
  • Remove
  • IsEmpty

IMPORTANT: Be sure to craft your input tests to ensure that your node removal works correctly.

3 QUESTIONS

1. What is the advantage of the ChunkList approach as opposed to the Unsorted link list implementation given in Chapter 3?

2. What would be the implications of increasing the size of ARRAY_SIZE to a very large value?

3. What is the big O of:

  • Append
  • GetLength
  • GetIndex
  • Search
  • Print
  • Remove
  • IsEmpty

4. Compare placing a new element into the FIRST available empty space versus placing a new element in the tail chunk. What are the advantages and disadvantages to automatically placing values at the tail node?

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.