# Question 1 Implement the OrderedSetclass as defined in Assignment...

## Question

Question 1
Implement the OrderedSetclass as defined in Assignment 1 using a linked list. Use the same program from assignment 1 to demonstrate your class.Compare the performance of the array implementation versus the linked list one.
Question 2
Write a method that takes a linked list of integers and rearranges the nodes so that the integers stored are sorted into the order of smallest to largest, with the smallest integer in the node at the head of the list. Your method should preserve repetitions of integers. If the original list had any integers occurring more than once, then the changed list will have the same number of each integer. Use the following specification:
// Postcondition: The return value is a head reference
// of a linked list with exactly thesame entries as
// the original list (including repetitions if any), but
// the entries in thislist are sorted from smallest to
// largest. The original linked list is no longer available
Your method will implement the following algorithm (which is often called selection sort): The algorithm removes nodes one at a time from the original list and adds the nodes to a second list until all the nodes have been moved to the second list. The second list will then be sorted.
// Pseudocode for selection sort:
While (the first list still has some nodes){
1.Find the node with the smallestelement of all the nodes in the first list.
2.Remove this node from the first list.
Note that your method will move entire nodes, not just elements, to the second list. Thus, the first list will get shorter and shorter until it is an empty list. Your method should not need to use the new operator since it is just moving nodes from one list to another (not creating new nodes)
Create a GUI application to test your method. Your application should allow the user to specify the required length of the linked list. Then, the program uses random numbers (generated between 1, 100) to create the list with the specified length and display it to the user. Finally, the program should display the sorted list.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package question1;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.Scanner;

import javax.swing.*;

/*
* Application class for Assignment 2 Question 1
* @version 2.0
*/
public class Application extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;

/*
* Constructor
* @throws FileNotFoundException
*/
public Application() throws FileNotFoundException {
JFileChooser chooser = new JFileChooser(".");
chooser.showOpenDialog(this);

// build OrderedSet from file
OrderedSet items = parseFile(chooser.getSelectedFile());

String[] columns = new String[] { "Item ID", "Item Name", "Quantity", "Selling Price" };

// actual data for the table in a 2d array
Object[][] data = items.get2DArray();

// create table with data
JTable table = new JTable(data, columns);

// add the table to the frame
JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

// add top panel to the frame
JPanel panelTop = new JPanel();

// add ascending button to the frame
JButton ascendingButton = new JButton("Sort by Ascending");
public void actionPerformed(ActionEvent e) {
items.sortAscending();
update(table, items);
}
});

// add descending button to the frame
JButton descendingButton = new JButton("Sort by Descending");
public void actionPerformed(ActionEvent e) {
items.sortDescending();
update(table, items);
}
});

// add bottom panel to the frame
JPanel panelBottom = new JPanel();

// construct label text
String labelText = "<html>";
labelText += "Maximum Price: \$" + String.format("%.2f", getMaximumPrice(items));
labelText += "<br>";
labelText += "Maximum Price Items:";
labelText += "<br>";
labelText += getMaximumPriceItems(items);
labelText += "<br>";
labelText += "Total Selling Value of All Items:" + "<br>";
labelText += "\$ " + String.format("%.2f", getTotalSellingValue(items));
labelText += "</html...

By purchasing this solution you'll be able to access the following files:
Solution.zip, Solution1.zip, Solution.txt, Solution1.txt, Solution.PNG, Solution1.PNG and Solution2.PNG.

\$67.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.