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

📄 chain.java

📁 简易的具有GPS导航功能的程序。仅有四个点
💻 JAVA
字号:

public class Chain 
{
	public ChainNode first;
    public Chain()
    {first=null;}
    public int IsEmpty(){if( first==null)return 1;return 0;}
    public int Length()
    {ChainNode current=first;
	int l=0;
    while(current!=null)
	{
		l++;
		current=current.link;
	}
	return l;
    }
    public	int Find(int k,int x)
    {
    	if(k<1)
  		  return 0;
  		ChainNode p=first;
  		int i=0;
  		while(p!=null&&i<k)
  		{
  			p=p.link;
  			i++;
  		}
  		if(p!=null)
  		{
  			x=p.data;
  			return 1;
  		}
  		return 0;
    }
    public  int Search(int x)
    {
    	ChainNode p=first;
	    int i=1;
	    while(p!=null&&p.data!=x)
		{
		  p=p.link;
		  i++;
		}
	    if(p==null)
	      return 0;
	    else
	      return i;
    }
    public void Delete(int y,int x)
    {
//    	删除指定的data值为y的元素,并存入x中
   	 if(first.data==y)
   		{first=first.link;}
   	 else 
   	 {
   		ChainNode t=first.link;
   	    ChainNode p=first;
   	    while(t.data!=y&&t!=null)
              {
   		  p=p.link;
   		  t=p.link;
              }
   	    if(t==null)
   	    	System.out.println("not found.");
   	    else
   		 p.link=t.link;
   	 }
    }
    
    public  void Insert(int k,int x)
    {
//    	在指定位置k后插入x
		ChainNode p=first;
		for(int i=1;i<k&&p!=null;i++)
		    p=p.link;
	    if(p==null&&p!=first)
	    	System.out.println("wrong.");
	    ChainNode y=new ChainNode();
		if(k!=0)
		{
		y.data=x;
		y.link=p.link;
		p.link=y;
		}
		else
		{
	        y.data=x;
			y.link=first;
			first=y;
		}
    }
    public void Add(int x)
    {
    	ChainNode y=new ChainNode();
		y.data=x;
	   	y.link=first;
		first=y;
    }
    public void Output()
    {
		ChainNode current;
		   for(current=first;current!=null;current=current.link)
			   System.out.print(current.data+" ");
		   System.out.println();
    }
	
}

⌨️ 快捷键说明

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