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

📄 linknode.java

📁 这个程序提供了JAVA很基础的CLASS的应用举例
💻 JAVA
字号:
import java.io.*;
class linknode{
	int data;
	linknode previous;
	linknode next;
	
	public linknode(){
		data=0;
		previous=null;
		next=null;
	}
	public linknode(int data,linknode p,linknode q){
		this.data=data;
		this.previous=p;
		this.next=q;
	}
	
	
	
	public void move(int n){
		data= n;
		}
	
	
	public linknode input(linknode p)throws IOException{
		int number;
		System.out.println("please input the numbers that you want to sort and sign the end with 0;");
		String s;
		InputStreamReader ir;
		BufferedReader in;
		ir=new InputStreamReader(System.in);
		in=new BufferedReader(ir);
	    s=in.readLine();
	    number=Integer.parseInt(s);
	    p.move(number);
	    s=in.readLine();
	    number=Integer.parseInt(s);
		while(number!=0)
		{
			linknode temp=new linknode();
			temp.move(number);
			temp.next=p;
			p.previous=temp;
			p=temp;
			s=in.readLine();
	        number=Integer.parseInt(s);     
		}
		linknode check=new linknode();
		check=p;
		System.out.println("the numbers that will be sorted are :");
		
		while(check!=null)
		{
			System.out.println(check.data);
			check=check.next;	
		}
		//System.out.println("OK");
		return p;
		
	}
	//It is right;
	
	
	
	
	
	
	 public void change(linknode p){
     	int temp;
     	linknode temp1=p;
     	linknode temp2=p;
     	linknode min;
     	while(temp1!=null)
     	{
     		temp2=temp1;
     		min=temp1;
     		while(temp2!=null)
     		{
     			if(temp2.data<min.data)
     			{
     				min=temp2;
     			}
     			temp2=temp2.next;     	
     		}
     		temp=min.data;
     		min.move(temp1.data);
     		temp1.move(temp);
     		temp1=temp1.next;	
     	} 
     	System.out.println("the numbers that have been sorted are :");
     	
     	while(p!=null)
     	{
     		System.out.println(p.data);
     		p=p.next;	
     	}
     	System.out.println("OK");
     }
     	
     	
     	
     	
     	
     	
     	
     	public static void main(String args[])throws IOException{
		linknode p=new linknode();
		p=p.input(p);
		p.change(p);
		}
			
	
}

	
	

		
		
		
		
		
	
	
	
	
	
	
	
			
    
     	


	

⌨️ 快捷键说明

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