InsertionSort - /* / InsertionSort.java Author: Lewis and...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // InsertionSort.java Author: Lewis and Loftus // // Solution to Programming Project 12.4 // // Demonstrates the insertion sort using a linked list //******************************************************************** public class InsertionSort { private SortNode list; //----------------------------------------------------------------- // Creates an initially empty linked list. //----------------------------------------------------------------- public InsertionSort() { list = null; } //----------------------------------------------------------------- // Adds an integer to the linked list //----------------------------------------------------------------- public void add(int value) { SortNode node = new SortNode(value); SortNode current = null; if (list == null) list = node; else { current = list; while (current.next != null) current = current.next; current.next = node; } } //----------------------------------------------------------------
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

InsertionSort - /* / InsertionSort.java Author: Lewis and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online