java创建循环链表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_37817685/article/details/83445000
/**
 * 
 */
/**   
 * @author jueying:   
 * @version 创建时间:2018-10-23 下午01:26:47   
 * 类说明   
 */
/**
 * @author jueying
 *
 */
public class Test6 {
	
	int top=-1;//栈顶指针
	int size=0;//栈大小
	 static Node headNode;
	
    int i=0;
	class Node{
		private Node next;//指针
		
		private Integer data;//数据域
		
	}

	
	//循环列表
	public void recicle(Node node,int data){
		if(i<=10){
			Node newNode=new Node();//创建新的结点
			newNode.data=new Integer(i);//设置数据域
			newNode.next=null;
			node.next=newNode;
			recicle(newNode,++i);
		}else{
			node.next=headNode;
		}
		
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		   Test6 test=new Test6();
		   headNode=test.new Node();//头指针
		   headNode.data=null;
		   new Test6().recicle(headNode,0);//循环链表
           System.out.println("创建后的循环链表是:");
           
           int k=0;
           while(headNode.next!=null&&k<=23){
        	   ++k;
        	   headNode=headNode.next;
        	   if(headNode.data!=null)
        	   System.out.print(headNode.data+" ");
           }
	}

}

猜你喜欢

转载自blog.csdn.net/weixin_37817685/article/details/83445000
今日推荐