Java--05:链表

初学Java--关于链表(ps:待整理)

class Node{
    public int value;
    public Node next;

public Node(int value){
    this.value=value;
    this.next=null;
    }
}
/*
public class Linklist{
// travel
public static Node traVel(Node head){
    Node cur=head;
    while(cur!=null){
        cur=cur.next;
    }
}     
public static Node pushFront(Node head,int value){
    Node newNode=new Node(value);
    newNode.next=head;
     return newNode;
}


public static Node pushBack(Node head,int value){
    Node newNode=new Node(value);
    if(head==null){
        newNode.next=head;
return newNode;        
    }else{
    Node last=getLast(head);
    last.next=newNode;    
    return head;
    }
}
public static Node getLast(Node head){
    Node cur=head;
    while(cur.next!=null){
        return cur.next;
    }
}

public static Node popBack(Node head){
    if(head==null){
        System.out.println("参数不合法");
        return null;
    }
    if(head.next==null){
        return null;
    }
}
public static void display(Node head){
    for(Node cur=head;cur!=null;cur=cur.next){
        System.out.printf("%d-->",cur.value);
    }
    System.out.pritln("null");
}

//please learn how to write the code not to copy code,try to  
public static Node pushFront(Node head,int value){
    //1、创建结点
    //2、让新结点的next指向head(头结点)
    //3、更新头结点的引用 不能用head=newNode ,head是形参
    Node newNode=new Node(value);
    newNode.next=head;
    return newNode;
}
public static Node getLast(Node head){
    
}
public static Node popBack(Node head){
    //找到倒数第二个结点 next.next ==null 
    //倒数第二个的节点指向null
    //把最后一个节点内存释放 GC会负责
    //更新头结点
    // 1.none 
    // 2.one
    
    if(head==null){
        System.out.println("不合法");
        return null;
    }
    // 头删
    if(head.next==null){
        return null;//or  return head.next
    }
    Node c=
    
}


public static void main(String[] args){
    head=pushFront(1);
    head=pushFront(2);
    head=pushBack(3);
    display(head);
    }
}
*/


关于链表我有很多代码都还及时没有练习。。。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值