Skip to content

Java program that reads a list of integers from standard input, stores them in a LinkedList, and sorts them in ascending order using the Java Collections Framework. Designed to run entirely from the command line, includes compile/run instructions and Javadoc documentation commands. Serves as the foundation for later modules.

License

Notifications You must be signed in to change notification settings

rsmx-code/project04-sorted-linked-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project 4 – Sorted Linked List (Java) Author: Reed McLean

Overview:

Reads integers from standard input, stores them in a java.util.LinkedList, sorts ascending using Collections.sort, and prints the result as a single space-separated line. Runs from the command line (no IDE required).

**Files in this submission:

  • SortedLinkedList.java – source code (uses Java Collections Framework)
  • README.md – this file
  • docs/ – generated Javadoc output (folder)
  • input.txt – sample test data (For grading/reference purposes)

Code Reuse (examples):

Standard Library Reuse: Uses java.util.LinkedList and Collections.sort(...) from the Java Collections Framework rather than writing custom list or sort logic.

Reusable Input Utility: readIntegersFromStdIn() cleanly encapsulates token scanning and integer parsing; it can be reused unchanged in future assignments that read integer streams.

Reusable Output Utility: printSpaceSeparated(List) prints any List as a single space-separated line and can be reused by later modules (the assignment notes this “infrastructure” will be reused).

Result: the program composes small, general helpers + library types, demonstrating reuse over re-implementation.


  1. How to compile:

Run:

javac SortedLinkedList.java


  1. How to run (choose one)

a. With a txt file (input.txt file included for reference of testing "5 3 8 9 -1 14 -6"):

Run:

java SortedLinkedList < input.txt

b. With inline values:

Run:

echo "5 -3 8 9 -1 14 -6" | java SortedLinkedList

c. Interactive (type numbers, then end input):

*Git Bash / WSL / macOS / Linux: press Ctrl+D to finish. *Windows CMD/PowerShell: press Ctrl+Z then Enter.

Run:

java SortedLinkedList


  1. Javadoc (required command) - Generate API docs into the docs/ folder

Run:

javadoc -d docs -author -version SortedLinkedList.java

*Open docs/index.html in a browser to view.


  1. Input format

Run:

java SortedLinkedList < input.txt

*Any whitespace-separated integers from standard input. *Non-integer tokens are safely ignored. Duplicates are preserved. Negatives allowed.

*Example input.txt

10 2 2 8 -1 hello 4 4 4 9 0 0

*Expected output:

-1 0 0 2 2 4 4 4 8 9 10


  1. Troubleshooting

*bash: input.txt: No such file or directory: -Create input.txt in the same folder you run the command from, or provide a full path.

*Could not find or load main class: -Ensure you compiled successfully and you’re running the command in the directory that contains SortedLinkedList.class. The class name and file name must match exactly.

*No output shown: -When running interactively, you must signal end-of-input (Ctrl+D or Ctrl+Z then Enter).


  1. Design (how it works)

Data flow: STDIN → Scanner → LinkedList → Collections.sort(...) → printSpaceSeparated(...) → STDOUT

Steps:

  1. Read tokens from standard input with Scanner. Non-integers are skipped, integers are appended to a LinkedList.

  2. Sort the list in ascending order using Collections.sort.

  3. Print the sorted list as a single space-separated line (no trailing space).

Reasons for LinkedList + Collections.sort:

-It satisfies the requirement for using the Collections Framework -It keeps the logic focused on composition (read → store → sort → print) rather than reinventing algorithms.

+---------+ +---------+ +-----------------+ +----------------------+ | STDIN | ---> | Scanner | ---> | LinkedList | ---+-> | Collections.sort(...)| +---------+ +---------+ +-----------------+ | +----------------------+ | v printSpaceSeparated(list) ---> STDOUT

About

Java program that reads a list of integers from standard input, stores them in a LinkedList, and sorts them in ascending order using the Java Collections Framework. Designed to run entirely from the command line, includes compile/run instructions and Javadoc documentation commands. Serves as the foundation for later modules.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages