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

📄 informationlist.java

📁 软件工程实践课程的答案哦
💻 JAVA
字号:
import java.io.*;
public class InformationList implements java.io.Serializable
{
	private Information first;
	private int size;
	
	public InformationList()
	{
		first=new Information();
		first.setNext(null);
		size=0;
	}
	
	public InformationList(Information element)
	{
		first.setNext(element);
		size++;
	}
	
	public void insert(Information obj)
	{
		Information p=first;
		
		while(p.getNext()!=null&&p.getNext().getScore()>obj.getScore())
		{
			p=p.getNext();
		}
		
		obj.setNext(p.getNext());
		p.setNext(obj);
		size++;
	}
	
	public Information search(int index)
	{
		//System.out.println("in search()");
		Information result=this.first;
		int p=0;
		while(p<index)
		{
			result=result.getNext();
			p++;
		}
		return result;
	}
	
	public void delete()
	{
		Information p=first.getNext();
		while(p!=null)
		{
			Information temp=p;
			p=p.getNext();
			temp.setNext(null);
			temp=null;
		}
		
		first.setNext(null);
	}
	
	public int getSize()
	{
		return this.size;
	}
	
	public Information getFirst()
	{
		return this.first;
	}
	
	public void displayList()
	{
		Information p=first.getNext();
		int i=1;
		while(p!=null&&i<=this.size)
		{
			//System.out.println("Rand"+i+" :"+p.getUserName()+" Score: "+p.getScore());
			p=p.getNext();
			i++;
		}
	}
	
	public void writeBack()
	{
		Information p=first.getNext();
			//System.out.println("Here in writeBack");
		try{
			ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("score.friend"));
			while(p!=null)
			{
				out.writeObject(p);
				p=p.getNext();
			}
			out.close();
		}catch(Exception e)
		{
		//	System.out.println("Here in writeBack  error");
		}
	}
	
	public void reLive()
	{
	//	System.out.println("Here in reLive");
		ObjectInputStream in=null;
		try{
			in=new ObjectInputStream(new FileInputStream("score.friend"));
			//System.out.println("Here in reLive34444433");
			while(true)
			{
				//System.out.println("Here in reLive333333");
				Information temp=(Information)in.readObject();
				//System.out.println("Name:"+temp.getUserName()+"  "+temp.getScore());
				this.insert(temp);
			}
			
			//in.close();
		}catch(EOFException e)
		{
			System.out.println("Here in reLive  error");
			if(in!=null)
			try{
				in.close();
				}catch(IOException ev)
				{
					System.out.println(ev);
				}
		}catch(ClassNotFoundException classNotFound)
		{
		}catch(IOException ioException)
		{
			
		}
		
	}
}

⌨️ 快捷键说明

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