Переглянути джерело

Created sorted list project

Tom Flucke 10 роки тому
батько
коміт
75516c2fa1
4 змінених файлів з 137 додано та 0 видалено
  1. 6 0
      Lab9/.classpath
  2. 17 0
      Lab9/.project
  3. 12 0
      Lab9/.settings/org.eclipse.jdt.core.prefs
  4. 102 0
      Lab9/src/MySortedList.java

+ 6 - 0
Lab9/.classpath

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Lab9/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Lab9</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 12 - 0
Lab9/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+#Mon Oct 19 11:07:42 PDT 2015
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

+ 102 - 0
Lab9/src/MySortedList.java

@@ -0,0 +1,102 @@
+import org.omg.CORBA.Current;
+
+
+public class MySortedList
+{
+	private Node head;
+	
+	private class Node
+	{
+		public int element;
+		public Node next;
+		
+		public Node(int element)
+		{
+			this.element = element;
+			this.next = null;
+		}
+	
+	}
+		
+	public MySortedList()
+	{
+		this.head = null;
+	}
+	
+	public void add(int newElm)
+	{
+		if (head == null)
+		{
+			head = new Node(newElm);
+		}
+		
+		else if(head.element > newElm)
+		{
+			Node tmp = new Node(newElm);
+			tmp.next = head;
+			head = tmp;
+		}
+		
+		else
+		{
+			Node current = new Node(newElm);
+			Node tmpHead = head;
+			
+			while ( tmpHead.next.element < current.element)
+			{
+				tmpHead = tmpHead.next;
+			}
+			
+			current.next = tmpHead.next;
+			tmpHead.next = current;
+		}
+	}
+	
+	
+	public void delete(int elm)
+	{
+		if (head == null)
+		{
+			//DO NOTHING
+		}
+		else
+		{
+			//Set tmp variable head, iterate w/while until tmp.next == null
+			//Stop when tmp.elem = elm
+			//
+		}
+	}
+	
+	public int max()
+	{
+		Node tmpHead = head;
+		
+		while (tmpHead.next != null)
+		{
+			tmpHead = tmpHead.next;
+		}
+		
+		return tmpHead.element;
+	}
+	
+	public int min()
+	{
+		return head.element;
+	}
+	
+	public void print()
+	{
+		Node tmpHead = head;
+		while (tmpHead.next != null)
+		{
+			System.out.print(tmpHead.element + " " );
+			tmpHead = tmpHead.next;
+		}
+		System.out.println();
+	}
+	
+	public boolean isEmpty()
+	{
+		return (head == null);
+	}
+}