【DataStructure&AlgorithmInJava】Ch05-LinkedListDemo1
2014-05-07 23:44
453 查看
linkedlist分析步骤-
1.画出链表图;
2.给每个Node分配具体reference(eg. 0x0012)
3.first, current.next 均代入地址值写code不容易出错
Note:
current Node均在块语句的最后update。
1.画出链表图;
2.给每个Node分配具体reference(eg. 0x0012)
3.first, current.next 均代入地址值写code不容易出错
Note:
current Node均在块语句的最后update。
class Node{ int data; Node next; Node(int d){ this.data=d; } public void displayNode(){ System.out.println("data="+this.data); } } class LinkedList{ Node first; LinkedList(){ first=null; } public boolean isEmpty(){ return first==null; } void insertFirst(int data){ Node newNode=new Node(data); newNode.next=first; first=newNode; } Node deleteFirst(){ //to clear this part,PLZ assign 0x0012 to "next box" Node temp =first; first=first.next; return temp; } void displayLinkedList(){ Node current = first; while(current!=null) { current.displayNode(); current=current.next; } } } class LinkedListDemo{ public static void main(String[] args) { LinkedList ll=new LinkedList(); ll.insertFirst(11); ll.insertFirst(22); ll.insertFirst(33); ll.insertFirst(44); ll.displayLinkedList(); System.out.println("========="); ll.deleteFirst(); ll.displayLinkedList(); } }
相关文章推荐
- 【DataStructure&AlgorithmInJava】Ch02-BinarySearchDemo
- 【DataStructure&AlgorithmInJava】Ch02-PersonArrayDemo
- 【DataStructure&AlgorithmInJava】Ch02-HighArrayDemo
- 【DataStructure&AlgorithmInJava】Ch02-OrderArray w binarySearch
- Data Structure Linked List: Reverse a Linked List in groups of given size
- Data Structure Linked List: Detect and Remove Loop in a Linked List
- Implementing the skip list data structure in java --reference
- [LinkedIn]linked List data structure so that add/insert, remove, get random in O(1) constant time
- Data Structure Linked List: Function to check if a singly linked list is palindrome
- bubble sort in linked list....(java version)
- Difference between LinkedList vs ArrayList in Java
- Insert & delte elements in doublely linked list
- Singly linked list algorithm implemented by Java
- (java)leetcode Delete Node in a Linked List
- [LeetCode-237]Delete Node in a Linked List(java)
- Difference between ArrayList and LinkedList in Java
- leetcode:Delete Node in a Linked List 【Java】
- Data Structure Linked List: Merge Sort for Linked Lists
- [Data Structure & Algorithm] 七大查找算法
- 《Data Structure And Algorithm Analysis In C++》读书笔记三