建站之星官方网站,手机版网站案例,做轴承生意的网站,企业网站的基本要素单链表的Java实现首先参考wiki上的单链表说明#xff0c;单链表每个节点包含数据和指向链表中下一个节点的指针或引用。然后看代码import java.lang.*;public class SinglyLinkeList{Node start;public SinnglyLinkedList(){this.startnull;}public void addFront(Object newD…单链表的Java实现首先参考wiki上的单链表说明单链表每个节点包含数据和指向链表中下一个节点的指针或引用。然后看代码import java.lang.*;public class SinglyLinkeList{Node start;public SinnglyLinkedList(){this.startnull;}public void addFront(Object newData){Node cache this.start; //store a reference to the current start nodethis.start new Node(newData,cache); //assign our start to a new node that has newData and points to our old start}public addRear(Object newData){Node cache start;Node current null;while((current cache.next) ! null) //find the last Nodecache cache.next;cache.next new Node(newData,null); //create a new node that has newData and points to null}public Object getFront(){return this.start.data; // return the front objects data}public class Node{public Object data; //the data stored in this nodepublic Node next; //store a reference to the next node in this singlylinkedlistpublic Node(Object data,Node next){this.data data;this.next next;}}}单链表翻转的Java实现循环方式public static LinkedList reverse(LinkedList Node) {LinkedList previous null;while (Node ! null) {LinkedList next Node.next;Node.next previous;previous Node;Node next;}return previous;}package linkedlists;public static LinkedList reverse(LinkedList node) {LinkedList headNode new LinkedList(1);快速排序的Java实现public class QuickSort {public static int SIZE 1000000;public int[] sort(int[] input) {quickSort(input, 0, input.length-1);return input;}public static void main(String args[]){int[] a new int[SIZE];for(int i0;ia[i] (int)(Math.random()*SIZE);}QuickSort mNew new QuickSort();long start System.currentTimeMillis();mNew.sort(a);long end System.currentTimeMillis();System.out.println(Time taken to sort a million elements : (end-start) milliseconds);}public void print(int[] inputData) {for(int i:inputData){System.out.print(i );}System.out.println();}private void quickSort(int arr[], int left, int right) {int index partition(arr, left, right);if (left index - 1)quickSort(arr, left, index - 1);if (index right)quickSort(arr, index, right);}private int partition(int arr[], int left, int right) {int i left, j right;int tmp;int pivot arr[(left right) / 2];while (i j) {while (arr[i] pivot)i;while (arr[j] pivot)j--;if (i j) {tmp arr[i];arr[i] arr[j];arr[j] tmp;i;j--;}}return i;}}