⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exam2_7.java

📁 关于数据结构的JAVA源代码
💻 JAVA
字号:
import java.util.Comparator;

public class Exam2_7{
	public static void linListSort(LinList L,Comparator mc){
		
		Node curr;
		curr = L.head.next;
		L.head.next = null;
		L.size = 0 ;
		
		while(curr != null){
			orderInsert(L,curr.element,mc);
			curr = curr.next;
		}
	}
	
	public static void orderInsert(LinList myList,Object x,Comparator mc){
		Node curr, pre;
		
		curr = myList.head.next;
		pre = myList.head;
		
		while(curr != null && (mc.compare(curr.element,x) == 1)){
			pre = curr;
			curr = curr.next;
		}
		
		Node temp = new Node((Integer)x,pre.next);		
		pre.next = temp;
		myList.size ++;
	}
	
	public static void main(String[] args){
		MyComparator mc=new MyComparator();
		LinList myList = new LinList();
		int s[] = {1, 3, 9, 11, 8, 6, 22, 16, 15, 10},n = 10;
		
		try{	
			
			for(int i = 0; i < n; i++){
				myList.insert(i,new Integer(s[i]));
			}
			
			System.out.print("排序前数据元素:\n");
			for(int i = 0; i < myList.size; i++){
				System.out.print(myList.getData(i)+"   ");
			}
			
			linListSort(myList,mc);
			
			System.out.print("\n排序后数据元素:\n");
			for(int i = 0; i < myList.size; i++){
				System.out.print(myList.getData(i)+"   ");
			}
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}	
	}	
}			

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -