//Timothy Zwart Cmpt_435_11_18F_x000D_
public class LinkedList {_x000D_
	_x000D_
_x000D_
	// The LinkedList Node class_x000D_
	private class Node{_x000D_
		_x000D_
		int data;_x000D_
		Node next;_x000D_
		_x000D_
		Node(int gdata)_x000D_
		{_x000D_
			this.data = gdata;_x000D_
			this.next = null;_x000D_
		}_x000D_
		_x000D_
	}_x000D_
	_x000D_
	// The LinkedList fields_x000D_
	Node head;_x000D_
	_x000D_
	// Constructor_x000D_
	LinkedList(int gdata)_x000D_
	{_x000D_
		this.head = new Node(gdata);_x000D_
	}_x000D_
	_x000D_
	public void Insertend(int gdata)_x000D_
	{_x000D_
		Node current = this.head;_x000D_
_x000D_
		while(current.next!= null)_x000D_
		{_x000D_
			current = current.next;_x000D_
		}_x000D_
		_x000D_
		Node newnode = new Node(gdata);_x000D_
		current.next = newnode;_x000D_
		_x000D_
	}_x000D_
	_x000D_
	public void Listprint()_x000D_
	{_x000D_
		Node current = this.head;_x000D_
_x000D_
		while(current!= null)_x000D_
		{_x000D_
			System.out.print(current.data + " ");_x000D_
			current = current.next;_x000D_
		}_x000D_
		_x000D_
		System.out.println();_x000D_
		_x000D_
	}_x000D_
	_x000D_
	public void Removemin() {_x000D_
	// Complete this method to remove the minimum value in a linkedlist_x000D_
	  _x000D_
	  //Current min element, place holder element, previous element in array,_x000D_
	  Node min = head;_x000D_
	  Node temp = head;_x000D_
	  Node prev =null;_x000D_
_x000D_
	   while (temp != null){_x000D_
	     // if the place holder element is not null then loop, since it is equal to the first element_x000D_
	      if(temp.next !=null){_x000D_
	        // if the next temp value is less than current min value replace current min value with the value of the next temp temp_x000D_
	        if(temp.next.data < min.data){_x000D_
	        min = temp.next;_x000D_
	        //set temp to previous element_x000D_
	        prev =temp;_x000D_
	        }_x000D_
	      }_x000D_
	      //set temp to then next temp because you are moving though the array_x000D_
	      temp=temp.next;_x000D_
	   }_x000D_
	   //if the minimum node is not the head move to the next value inorder to get to min value_x000D_
	   if (min != head){_x000D_
	     prev.next = min.next;_x000D_
	   }else{_x000D_
	     //if it is the head it shifts the elements over overwriting the current head with next head making the head now removed_x000D_
	     head = head.next;_x000D_
	   }_x000D_
	}_x000D_
	_x000D_
	public static void main(String[] args) {_x000D_
		_x000D_
		LinkedList exlist = new LinkedList(0);_x000D_
		_x000D_
		exlist.Insertend(1);_x000D_
		exlist.Insertend(5);_x000D_
		exlist.Insertend(2);_x000D_
		exlist.Insertend(7);_x000D_
		exlist.Insertend(10);_x000D_
		exlist.Insertend(3);_x000D_
		_x000D_
		exlist.Listprint();_x000D_
		//output: 0 1 5 2 7 10 3_x000D_
		_x000D_
		exlist.Removemin();_x000D_
		_x000D_
		exlist.Listprint();_x000D_
		//output should be: 0 1 5 2 7 3_x000D_
		_x000D_
		_x000D_
	}_x000D_
	_x000D_
	_x000D_
	_x000D_
_x000D_
}_x000D_

//Current min element, place holder element, previous element in array,_x000D_
//Timothy Zwart Cmpt_435_11_18F_x000D_
public class LinkedList {_x000D_
	_x000D_
_x000D_
	// The LinkedList Node class_x000D_
	private class Node{_x000D_
		_x000D_
		int data;_x000D_
		Node next;_x000D_
		_x000D_
		Node(int gdata)_x000D_
		{_x000D_
			this.data = gdata;_x000D_
			this.next = null;_x000D_
		}_x000D_
		_x000D_
	}_x000D_
	_x000D_
	// The LinkedList fields_x000D_
	Node head;_x000D_
	_x000D_
	// Constructor_x000D_
	LinkedList(int gdata)_x000D_
	{_x000D_
		this.head = new Node(gdata);_x000D_
	}_x000D_
	_x000D_
	public void Insertend(int gdata)_x000D_
	{_x000D_
		Node current = this.head;_x000D_
_x000D_
		while(current.next!= null)_x000D_
		{_x000D_
			current = current.next;_x000D_
		}_x000D_
		_x000D_
		Node newnode = new Node(gdata);_x000D_
		current.next = newnode;_x000D_
		_x000D_
	}_x000D_
	_x000D_
	public void Listprint()_x000D_
	{_x000D_
		Node current = this.head;_x000D_
_x000D_
		while(current!= null)_x000D_
		{_x000D_
			System.out.print(current.data + " ");_x000D_
			current = current.next;_x000D_
		}_x000D_
		_x000D_
		System.out.println();_x000D_
		_x000D_
	}_x000D_
	_x000D_
	public void Removemin() {_x000D_
	// Complete this method to remove the minimum value in a linkedlist_x000D_
	  _x000D_
	  //Current min<SUF>
	  Node min = head;_x000D_
	  Node temp = head;_x000D_
	  Node prev =null;_x000D_
_x000D_
	   while (temp != null){_x000D_
	     // if the place holder element is not null then loop, since it is equal to the first element_x000D_
	      if(temp.next !=null){_x000D_
	        // if the next temp value is less than current min value replace current min value with the value of the next temp temp_x000D_
	        if(temp.next.data < min.data){_x000D_
	        min = temp.next;_x000D_
	        //set temp to previous element_x000D_
	        prev =temp;_x000D_
	        }_x000D_
	      }_x000D_
	      //set temp to then next temp because you are moving though the array_x000D_
	      temp=temp.next;_x000D_
	   }_x000D_
	   //if the minimum node is not the head move to the next value inorder to get to min value_x000D_
	   if (min != head){_x000D_
	     prev.next = min.next;_x000D_
	   }else{_x000D_
	     //if it is the head it shifts the elements over overwriting the current head with next head making the head now removed_x000D_
	     head = head.next;_x000D_
	   }_x000D_
	}_x000D_
	_x000D_
	public static void main(String[] args) {_x000D_
		_x000D_
		LinkedList exlist = new LinkedList(0);_x000D_
		_x000D_
		exlist.Insertend(1);_x000D_
		exlist.Insertend(5);_x000D_
		exlist.Insertend(2);_x000D_
		exlist.Insertend(7);_x000D_
		exlist.Insertend(10);_x000D_
		exlist.Insertend(3);_x000D_
		_x000D_
		exlist.Listprint();_x000D_
		//output: 0 1 5 2 7 10 3_x000D_
		_x000D_
		exlist.Removemin();_x000D_
		_x000D_
		exlist.Listprint();_x000D_
		//output should be: 0 1 5 2 7 3_x000D_
		_x000D_
		_x000D_
	}_x000D_
	_x000D_
	_x000D_
	_x000D_
_x000D_
}_x000D_
