EECE.2160: ECE Application Programming

Similar documents
EECE.2160: ECE Application Programming

1. Introduction. 2. Deliverables

EECE.2160: ECE Application Programming

EECE.2160: ECE Application Programming Spring 2018 Programming Assignment #6: Using Arrays to Count Letters in Text Due Wednesday, 4/4/18, 11:59:59 PM

PIC 10B Lecture 1 Winter 2014 Homework Assignment #2

PIC 10B Lecture 1 Winter 2014 Homework Assignment #3

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

(b) Vsource R2 Vsource

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

15-213/18-213/15-513, Fall 2017 C Programming Lab: Assessing Your C Programming Skills

Introduction to Computer Science Midterm 3 Fall, Points

Dynamic Data Structures (II)

Data Structures (CS301) LAB

15-213/18-213/15-513, Spring 2018 C Programming Lab: Assessing Your C Programming Skills

HOT-Compilation: Garbage Collection

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

OOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1

Computer Programming: C++

BBM 201 DATA STRUCTURES

Pointers. Memory. void foo() { }//return

Programming Assignment #4 Arrays and Pointers

CS 455 Final Exam Fall 2016 [Bono] December 13, 2016

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CSC 172 Data Structures and Algorithms. Lecture #8 Spring 2018

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts)

CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005

SPRING 2017 CSCI 304 LAB1 (Due on Feb-14, 11:59:59pm)

EECE.2160: ECE Application Programming Spring 2018 Programming Assignment #1: A Simple C Program Due Monday, 1/29/18, 11:59:59 PM

FALL 2017 CSCI 304 LAB1 (Due on Sep-19, 11:59:59pm)

CIS 190: C/C++ Programming. Lecture 12 Student Choice

Linked Lists and Abstract Data Structures A brief comparison

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Programming Assignment 2 ( 100 Points )

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

! A data structure representing a list. ! A series of dynamically allocated nodes. ! A separate pointer (the head) points to the first

CS 11 C track: lecture 6

Prelim 1. CS2110, October 2, 2014, 5:30 PM Extra Total Question TrueFalse Multiple Object Oriented

CMSC 341 Lecture 7 Lists

1. Introduction. 2. Project Submission and Deliverables

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

EECE.2160: ECE Application Programming Fall 2017

CS 103 Unit 15. Doubly-Linked Lists and Deques. Mark Redekopp

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

Lab 8: Ordered Search Results

Computer Science E-119 Fall Problem Set 3. Due before lecture on Wednesday, October 31

Debugging Techniques. CEFET Engineering Week

Implementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations

Lab 5 - Linked Lists Git Tag: Lab5Submission

EE 422C HW 6 Multithreaded Programming

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues

Linked List Practice Questions

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CS 314 Final Fall 2012

Write a program that creates in the main function two linked lists of characters and fills them with the following values:

Ashish Gupta, Data JUET, Guna

FORM 2 (Please put your name and form # on the scantron!!!!)

ITP 165: Introduction to C++ Programming Homework 10: Superhero fight Due: 11:59pm, December 1 st, 2017

ENCM 369 Winter 2017 Lab 3 for the Week of January 30

CS2 Practical 1 CS2A 22/09/2004

C Programming, Autumn 2013, Exercises for the Second Week

Programming Assignment 2

EECE.4810/EECE.5730: Operating Systems Spring 2018 Programming Project 3 Due 11:59 PM, Wednesday, 4/18/18 Monday, 4/30/18

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSCI 135 Programming Exam #1 Fundamentals of Computer Science I Fall 2014

(More) Fun with Pointers and Linked Lists! CS 16: Solving Problems with Computers I Lecture #17

1 Deletion in singly linked lists (cont d) 1 Other Functions. 1 Doubly Linked Lists. 1 Circular lists. 1 Linked lists vs. arrays

Lab 4 - Linked Lists

CS106X Handout 27 Winter 2015 February 18 th, 2015 Section Handout. list after call braid(list) 3 3 à 3

CS 051 Homework Laboratory #2

COMP2402: Mid-term Review Questions

EE 355 Unit 11b. Doubly-Linked Lists and Deques. Mark Redekopp

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

+ Abstract Data Types

Linked lists. Comp Sci 1575 Data Structures. Definitions. Memory structure. Implementation. Operations. Comparison

CSC 172 Data Structures and Algorithms. Lecture #9 Spring 2018

Lab 03 - x86-64: atoi

CS61, Fall 2012 Section 2 Notes

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

COMP 524 Spring 2018 Midterm Thursday, March 1

Introduction to Programming in C Department of Computer Science and Engineering

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

Introduction to Computer Systems. Exam 2. April 10, Notes and calculators are permitted, but not computers.

Writeup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Parallel access to linked data structures

Binary Trees and Binary Search Trees

Templates and Operator Overloading in C++

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

1. Overview This project will help you understand address spaces and virtual memory management.

Lecture 8: Iterators and More Mutation

CSE 333 Midterm Exam July 24, Name UW ID#

EE355 Lab 5 - The Files Are *In* the Computer

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

Transcription:

Fall 2017 Programming Assignment #10: Doubly-Linked Lists Due Monday, 12/18/17, 11:59:59 PM (Extra credit ( 5 pts on final average), no late submissions or resubmissions) 1. Introduction This assignment deals with the combination of dynamic memory allocation and structures to create a common data structure known as a doubly-linked list, which is shown in Figure 1. Figure 1: Doubly-linked list in which each node contains three fields--pointers to the previous and next nodes in the list, and a single integer as data. (source: http://en.wikipedia.org/wiki/doubly-linked_list) The boxes holding 'X' at the start and end of the list show the first and last nodes have NULL pointers for their previous and next pointers, respectively. Pointers to the first and last nodes, which allow you to traverse the list in either direction, are not shown. The list you will implement is a sorted doubly-linked list in which each node stores two double-precision values, and the nodes are sorted from lowest to highest value. You will complete six functions, which allow you to add or delete a node, find a node containing a given value, or print the entire contents of the list. There are two versions of the find and print functions, one for each possible traversal direction. 2. Deliverables This assignment uses multiple files, each of which is provided on the course web page: prog10_main.c: Main program. Do not change the contents of this file. DLList.h: Header file that contains structure definitions and function prototypes to be used in this assignment. Do not change the contents of this file. DLList.c: Definitions for the functions described in DLList.h. You should only complete the functions in this file do not change any of the #include statements, structure definitions, or function prototypes (i.e., function return types and arguments). To complete this assignment, you will complete each of the functions in DLList.c. If each function is properly written, the entire program will work correctly. Submit all three files by uploading these files to your Dropbox folder. Place the files in directly in your shared folder do not create a sub-folder to hold them. Ensure your file names match the names specified above. Failure to meet this specification will reduce your grade, as described in the program grading guidelines. 1

3. Specifications The main program (prog10_main.c) recognizes five different commands, most of which call a function described in DLList.h and defined in DLList.c: add: Prompts the user to enter two values, then adds those values to the list using the addnode() function. delete: Prompts the user to enter a value, then removes that value from the list using the deletenode() function. find: Prompts the user to enter a value, then searches the list for that value using both the findfwd() and findrev() functions. print: Prints the entire list using the printfwd() and printrev() functions. DLList.h contains function prototypes as well as structure definitions. The doubly-linked list is defined using two structures: DLNode: A single node in the list, which contains four items: o prev: A pointer to the previous node in the list. This pointer is NULL if the node is the first entry in the list. o next: A pointer to the next node in the list. This pointer is NULL if the node is the last entry in the list. o val1, val2: Two double-precision values, which are the data stored in this node. The list should be sorted so nodes are sorted from lowest to highest value, based on their val1 fields. If two nodes have the same val1 values, they should be sorted from lowest to highest based on their val2 fields. DLList: A structure that contains two pointers, firstnode and lastnode, which point to the first and last nodes in the list, respectively. o If the list is empty, both pointers are NULL. o If the list holds only one node, both firstnode and lastnode point to that node. You are responsible for completing each of the functions in DLList.c described below again, note that this file is the only one you should modify: DLNode *findfwd(dllist *list, double v, int *num) Search list for a node in which only the val1 field matches v. Search starts with the first node in the list. The function should calculate the number of iterations required to find the value and store it at the address pointed to by num. Return a pointer to the node with the matching value if it is found, and return NULL otherwise. DLNode *findrev(dllist *list, double v, int *num) Same as findfwd(), but the search begins with the last node and traverses the list in reverse. 2

3. Specifications (continued) Three of the other four functions to be completed are: void printfwd(dllist *list) Go through the entire list, starting with the first node, and print the values stored in each node on their own line. If the list is empty, print List is empty. void printrev(dllist *list) Same as printfwd(), but prints the last node first and traverses the list in reverse. void addnode(dllist *list, double v1, double v2) Create a new node holding values v1 and v2, then add that node to the list. Notes: The process for inserting a node in a doublylinked list is below, with pointer changes shown in the figure (source: http://www.cs.grinnell.edu/ ~walker/courses/161.sp12/modules/lists/ reading-lists-double.shtml): o Create a new node o Place the data in the node (v1 in the val1 field, v2 in val2) o Set the prev and next pointers inside the new node to point to the correct nodes. o Modify next in the node before the new one. o Modify prev in the node after the new one. This function must maintain the list order all val1 fields should be sorted from lowest to highest, with val2 fields used to sort nodes with matching val1 fields. You must therefore find the correct location before inserting the node into the list. There are three special cases to account for: o The new node is the only thing in the list (i.e., list is empty at start of function) o The new node becomes the first node in the list (but list contains other nodes) o The new node becomes the last node in the list (but list contains other nodes) 3

3. Specifications (continued) The final function to be completed is: void delnode(dllist *list, double v) Find the node containing the word v (only testing the val1 field of each node), then remove that node from the list. If no matching node is found, do not modify the list. A few notes: This function essentially does the opposite of the addnode() function, once the node to be removed has been found: o Modify next in the node before the chosen node. o Modify prev in the node after the chosen node. o Remove the chosen node. Removal of a node implies that any space that was dynamically allocated when creating the node must be deallocated to remove it. There are, once again, three special cases to account for: o The node to be removed is the only thing in the list (both first and last) o The node to be removed is the first node in the list (but not also the last node) o The node to be removed is the last node in the list (but not also the first node) 4. Hints Design process: I would suggest handling the program in the following order: 1. Start with the two print functions, and at least test the case where the list is empty. 2. Next, write the addnode() function. At least two of the first three cases you test will have to be special cases, since the list starts out as an empty list, and the second word you add will become either the first or last item in the list. You can test the operation of this function, as well as the print functions, by running the main program and alternating add and print commands. 3. Once you have handled all possible cases for addnode(), write the findfwd() and findrev() functions. Test these functions by adding items to the list and using the find command. 4. Finally, write the delnode() function. Test this function by adding items to the list, using the delete command, and then using the print command to show the results. Be sure to test all of the special cases. If you encounter errors, running your program in the debugger is the most effective way to find them. Recall that the debugger offers the ability to step into a function (F11 in Visual Studio) so that you can see each step within the function you have written, or simply step over (F10) the function and treat a function call as a single statement. 4

Similarities: Please note that many of the functions are similar to those used for a sorted singly-linked list, which was discussed in lectures 33-36. In particular: The findfwd() and printfwd() functions are virtually identical to the findnode() and printlist() functions. The addnode() and delnode() functions are similar an additional pointer in each node makes the functions slightly more complicated, but also makes it easier to identify the nodes before and after the one being added or deleted. Handling first and last nodes: The addnode() and delnode() functions must each deal with three special cases involving the first and last nodes in the list: The DLList structure contains pointers to the first (firstnode) and last (lastnode) nodes in the list. Therefore, any operation that changes what node is first or last must also change the appropriate pointer in the DLList structure, not just the prev and next pointers in the DLNode structures within the list. In each node at one end of the list, at least one of the pointers in that node is a NULL pointer. In the first node, prev is NULL; in the last node, next is NULL. You must account for these NULL pointers when working with these nodes. 5. Grading As noted in class, grading for this program will be stricter than normal. In particular: A program that does not compile will receive a grade of 0. A program that does not generate proper output will receive minimal credit. o If your functions work but the program doesn t show the results, you will receive some credit for writing functions that appear correct but will be penalized heavily for making it impossible to test those functions. The general point breakdown will be: Find functions (findfwd(), findrev()): 25 points o Each function must traverse list in proper order, return the correct node pointer, and count the number of iterations to find the value if present. Print functions (printfwd(), printrev()): 25 points o Print functions must print list in proper order with correct formatting. addnode(): 25 points o Function must maintain a sorted list based on val1 values, with val2 values used to sort nodes that duplicate val1 values. delnode(): 25 points o Function must delete appropriate node. For full credit, this function should only use a single node pointer, rather than the prev/cur pointer pair required in a singly-linked list. 5

6. Test Cases Your output should match these test cases exactly for the given input values. I will use these test cases in grading of your lab, but will also generate additional cases that will not be publicly available. Note that these test cases may not cover all possible program outcomes. You should create your own tests to help debug your code and ensure proper operation for all possible inputs. I ve copied and pasted the output from each test case below, rather than showing a screenshot of the output window. User input is underlined in each test case, but it won t be when you run the program. Enter values to be added: 1.2 3.4 Enter values to be added: 5.6 7.8 Enter values to be added: 0.1 0.1 Enter values to be added: 3 3.33 Enter command: print Contents of list (low to high): 0.10 0.10 3.00 3.33 5.60 7.80 Contents of list (high to low): 5.60 7.80 3.00 3.33 0.10 0.10 Enter command: find Enter value to be found: 1.2 1.20 found in node: Forward search: 2 iterations Reverse search: 3 iterations Enter values to be added: 4 2 Enter values to be added: 4 6 6

6. Test Cases (continued) Enter values to be added: 4 4 Enter command: print Contents of list (low to high): 0.10 0.10 3.00 3.33 4.00 2.00 4.00 4.00 4.00 6.00 5.60 7.80 Contents of list (high to low): 5.60 7.80 4.00 6.00 4.00 4.00 4.00 2.00 3.00 3.33 0.10 0.10 Enter command: find Enter value to be found: 4.1 4.10 not found in list Enter command: find Enter value to be found: 3.4 3.40 not found in list Enter command: delete Enter value to be deleted: 5.6 Enter command: delete Enter value to be deleted: 0.1 Enter command: delete Enter value to be deleted: 3 7

6. Test Cases (continued) Enter command: print Contents of list (low to high): 4.00 2.00 4.00 4.00 4.00 6.00 Contents of list (high to low): 4.00 6.00 4.00 4.00 4.00 2.00 Enter command: exit 8