<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Linked Lists - CSCI 151: Data Structures</title><link>https://cs.oberlin.edu/~cs151/lab-4/index.html</link><description>Lab 4 Goals Implement a doubly-linked list to reinforce our understanding how it works Explore the use of iterators for iterating through collections without using indices Practice using unit tests to help us debug our code Explore the application of linked lists for a real-world problem Welcome to your fourth CSCI 151 lab! The lab can be started by following this link to create a copy of the assignment for you on GitHub: Accept Assignment</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 07 Aug 2021 09:07:24 -0400</lastBuildDate><atom:link href="https://cs.oberlin.edu/~cs151/lab-4/index.xml" rel="self" type="application/rss+xml"/><item><title>Nodes</title><link>https://cs.oberlin.edu/~cs151/lab-4/w-part-1/index.html</link><pubDate>Sat, 07 Aug 2021 09:07:24 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/w-part-1/index.html</guid><description>In the main part of the lab, you’re going to be implementing linked lists so we’re going to walk through writing a simple linked list data structure. A linked list consists of a sequence of nodes. A node is a very simple data structure that contains an element and a link to the next node in the sequence.
Nodes Open the LinkedNode.java file from the Lab 4 repository.
We want to be able to use our LinkedNode class to hold any given type of object, so change:</description></item><item><title>Iteration</title><link>https://cs.oberlin.edu/~cs151/lab-4/w-part-2/index.html</link><pubDate>Sat, 07 Aug 2021 09:07:24 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/w-part-2/index.html</guid><description>The act of iterating through a data structure in order to examine or operate on each element is fundamental in computer science and shows up again and again. You have done this many times already. For example, in Java, if you have an ArrayList&lt;Integer&gt;, you can iterate through it and sum all of the elements.
ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;(); int sum = 0; // Add some elements to the list. for (int i = 0; i &lt; list.size(); i++) { sum += list.get(i); } Although this approach works quite well with an ArrayList, it really breaks down when we switch data structures to something like a LinkedList. In lab 4, you will be implementing your own LinkedList. The problem comes from the list.get(i) method. Recall that a linked list stores a pointer to the head of the list (and perhaps a pointer to the tail of the list). In order to get to the element at index i, the implementation of get() has to start at the head of the list and walk through the linked list of nodes. This code would look something like</description></item><item><title>Iterables</title><link>https://cs.oberlin.edu/~cs151/lab-4/w-part-3/index.html</link><pubDate>Sat, 07 Aug 2021 09:07:24 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/w-part-3/index.html</guid><description>The reason that the for (T obj : collection) works is that all of the Java collections implement the Iterable interface (it is even a super-interface of the List interface that we have been working with). The Iterable interface has the method
Iterator&lt;T&gt; iterator(); that returns an Iterator object that allows us to loop through the items in a collection without having to use indices. We can create our own classes that implement Iterable and work with for-each loops.</description></item><item><title>Drawing Doubly Linked Lists</title><link>https://cs.oberlin.edu/~cs151/lab-4/w-part-4/index.html</link><pubDate>Sat, 07 Aug 2021 09:07:24 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/w-part-4/index.html</guid><description>A great technique for coming up with algorithms to act on data structures is drawing out what the final data structure will look like and thinking about what needs to be updated to get it there. With a partner, draw a doubly linked list like the above after each of the following changes. You should start with an empty list and do the following steps.
Adding item “a” to the beginning of the list Adding item “b” to the end of the list Adding item “c” at index 1 of the list Adding item “d” at index 2 of the list Removing the item from the beginning of the list Removing the item from the end of the list Removing the item from index 1 of the list To submit your work, take a picture of your drawings after each step above and add the picture(s) to your github repository for Lab 4. If you upload it via the github website, please make sure you run git pull on the lab machine so you don’t run into issues later.</description></item><item><title>Starting MyLinkedList</title><link>https://cs.oberlin.edu/~cs151/lab-4/l-part-1/index.html</link><pubDate>Sun, 13 Jun 2021 17:08:08 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/l-part-1/index.html</guid><description>Data Structure Overview In the first few parts of this lab, we will be creating our own implementation of the doubly linked list data structure to better understand how its implementation and behavior differ from the array list that we created in Lab 3, even though both provide the same fundamental functionality as Lists. This will build on the singly linked list that you started in Part 1 of the Warmup – recall from class that a doubly linked list can transverse the list both forwards and backwards, whereas a singly linked list only traverses the list in one direction (usually forward).</description></item><item><title>Inserting and Retrieving Items</title><link>https://cs.oberlin.edu/~cs151/lab-4/l-part-2/index.html</link><pubDate>Sun, 13 Jun 2021 17:08:08 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/l-part-2/index.html</guid><description>Overview In this part of the lab, we will add functionality to our MyLinkedList class to insert and retrieve items from our data structure. We will also continue to practice using unit tests to debug and validate our implementation.
Adding Items to MyLinkedList The first main operation we will work on programming is adding items to our data structure since we cannot do anything unless it is storing data. Given how linked lists store data, we need to first create a private helper method that will simplify the processing of adding data to our doubly linked list.</description></item><item><title>Replacing and Removing Items</title><link>https://cs.oberlin.edu/~cs151/lab-4/l-part-3/index.html</link><pubDate>Sun, 13 Jun 2021 17:08:08 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/l-part-3/index.html</guid><description>Overview In this part of the lab, we will add the remaining functionality to our MyLinkedList class to replace and remove items from our data structure, as well as a few methods for affecting the current state of the data structure. We will also continue practicing using unit tests to debug and validate our implementation.
Replacing Items in MyLinkedList To allow us to replace the item at a given index of the linked list, we will use the public T set(int index, T item) method. This method should:</description></item><item><title>Doubly Linked List Iterator</title><link>https://cs.oberlin.edu/~cs151/lab-4/l-part-4/index.html</link><pubDate>Sun, 13 Jun 2021 17:08:08 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/l-part-4/index.html</guid><description>Overview In this part of the lab, we will create a ListIterator called MyLinkedListIterator for our MyLinkedList class that will allow us to iterate through our data structure without accessing any item by its index, similar to how we looped in Part 3 of the Warmup. Given the way a linked list is organized, this type of access is faster than using the get method whenever we want to loop over successive items in the list.</description></item><item><title>Fair and Swift Ticket Allocation</title><link>https://cs.oberlin.edu/~cs151/lab-4/l-part-5/index.html</link><pubDate>Sun, 13 Jun 2021 17:08:08 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/l-part-5/index.html</guid><description>Application Overview In many areas of life, we provide goods and services to people ordered by when they line up for access (e.g., grocery store checkouts, TSA security lines). While this might promote one notion of fairness by avoiding “cutting in line” (as we will explore soon with the queue data structure), it can also result in inequalities in some applications, especially when people might make multiple purchases at once.</description></item><item><title>Wrap Up</title><link>https://cs.oberlin.edu/~cs151/lab-4/wrap-up/index.html</link><pubDate>Fri, 06 Aug 2021 20:21:56 -0400</pubDate><guid>https://cs.oberlin.edu/~cs151/lab-4/wrap-up/index.html</guid><description>Congratulations! You have now implemented our second data structure (the Linked List) and created an application using it to complete your fourth lab of the semester!
Filling Out the README.md The final task for every lab is to edit the README file in the lab assignment repository. Each week, you’ll be asked to answer three questions regarding collaboration, time spent on the lab, and the Honor Code.
A reminder to make sure you have consulted the Honor Code policy in the course syllabus for information about how to sign the Honor Code and about acceptable collaboration in CSCI 151. Your instructor is also happy to answer any questions about the Honor Code – just let us know.</description></item></channel></rss>