Answered step by step
Verified Expert Solution
Question
1 Approved Answer
NCBC 2006-Data Structures I Assignment #3 A gentle introduction to linked lists Please remember to read and follow all of the assignment guidelines. In
NCBC 2006-Data Structures I Assignment #3 A gentle introduction to linked lists Please remember to read and follow all of the assignment guidelines. In particular, for this problem, remember to write your own routines and classes for dealing with linked lists-don't just reproduce the ones in the textbook or notes. Also keep in mind the essentials of program design; each basic operation you perform should be in one (or more, if necessary) method (s). For this assignment, you are to write a Java program to perform some manipulations on a list of students' marks, similar to the assignment 1. Given the ever-increasing class sizes at universities, your program should use a linked list to store the mark for each student. You may be able to use part of code from assignment 1 if you want to. Each node in the linked list should contain two pieces of data-the student's number (an integer) and that student's mark (a double). In the linked list, student marks should be stored in order of descending mark values; thus, the first student in the linked list should be the one with the highest mark, the second in the list should have the second highest mark, and so on. This order should be maintained for each student added to the list (when you add a new node to the linked list, insert it at the correct position to maintain sorted order). Input data to your program will consist of a file containing student number and mark pairs, one per line. For example, the file might contain: 11111 63.5 22222 59.9 33333 82.4 Every time you read in a line from the file, dynamically create a new node containing that student's number and mark, and insert it in the correct position in the linked list. For example: After reading the first line of data: Top-> Second line: 11111 22222 63.5 59.9 63.5 Top-> Third line: Top-> 33333 11111 22222 82.4 63.5 59.9 After reading in all of the data and storing it in your list, you should perform two operations on the list. First, you should print out the contents of the linked list, from start to finish, nearly in a table. For example: Student Number: Mark: 33333 82.4 11111 22222 63.5 59.9 Secondly, you should print out the median mark in the list. However, there are two rules you must follow. First, the method you use to calculate the median mark must be recursive. The function/method which calculates the median cannot use any loops, or call any functions which use loops. This function should return the node in the list which contains the median mark. Secondly, in order to find the median, you need to know how many items in total are in the list. Your recursive function must calculate that number (also recursively); you may not keep track of this count elsewhere your program. Your recursive solution should only examine each node only once, and the depth of the recursion should be equal to the number of nodes in the list. In order to make this (slightly) easier, the normal mathematical calculation for determining median is eased somewhat-if you have an even number of nodes in your list, either of the two marks in the middle may be considered the median (for example, if your list contains the four marks {90, 80, 70, 60}, your function could return either 80 or 70 for the median). From the example above, your program should print out something like: The median mark is 63.5, by student number 11111. You do not require to have any interface, but are encouraged to do so. Submission: Upload into CMS with the source code of your program, and the output of running your program twice, using the following two sets of input data (save as files, test1.txt and test2.txt): Data set #1: 11111 63.5 22222 59.9 33333 82.4 44444 70.1 55555 72.3 66666 89.5 77777 68.7 88888 53.2 99999 66.8 Data set #2: 58585 72.9 43434 80.0 90909 82.3 87878 62.1 62626 64.7 71717 74.6 92929 51.5 36363 55.9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Complete Java Program import javautilScanner import javaioFile import javaioFileNotFoundException class Student int number double mark Student next public Studentint number double mark thisnumber numb...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started