单链表反转(Singly Linked Lists in Java)博客分类:数据结构及算法Java代码packagedsa.linkedlist;publicclassNode{Edata;Nodenext;}Java代码packagedsa.linkedlist;publicclassRever...
分类:
编程语言 时间:
2014-06-28 17:47:36
阅读次数:
232
队列相信大家也很熟悉,我就不说了。本文采用LinkedList提供的方法以支持队列的行为,并且它实现了Queue的接口,因此LinkedList可以作为Queue的一种实现。通过将LinkedList向上转型为Queue,下面的示例使用了在Queue接口中与Queue相关的方法: 1 package...
分类:
编程语言 时间:
2014-06-28 15:42:36
阅读次数:
221
7.集合框架 集合: Collection接口 : -List接口 (有序的,通常允许重复) -实现类:ArrayList(用可变数组实现,不是同步的(线程不安全)) :适合查找,添加 LinkedList(双向链表的实现,不是同步的):适合插入,删除 Vector(用...
分类:
编程语言 时间:
2014-06-20 20:06:23
阅读次数:
226
题目
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only const...
分类:
其他好文 时间:
2014-06-18 11:53:39
阅读次数:
138
题目
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
If the number of nodes is not a multiple of k then left-out nodes in the end should rem...
分类:
其他好文 时间:
2014-06-17 22:15:52
阅读次数:
299
题目
Given a linked list, remove the nth node from the end of list and return its head.
For example,
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from th...
分类:
其他好文 时间:
2014-06-17 21:38:12
阅读次数:
193
题目
Merge k sorted
linked lists and return it as one sorted list. Analyze and describe its complexity.
方法
使用归并排序的思想,两两合并,直到最终变成一个。
public ListNode mergeKLists(ArrayList lists) {...
分类:
其他好文 时间:
2014-06-17 21:34:41
阅读次数:
183
在JAVA的util包中有两个所有集合的父接口Collection和Map,它们的父子关系: java.util +Collection 这个接口extends自 --java.lang.Iterable接口 +List 接口 -ArrayList 类 -LinkedList 类 -Vector 类...
分类:
编程语言 时间:
2014-06-15 20:23:51
阅读次数:
280
Java 中数组声明后不可修改 –跟C一样 ,C中往往会增加定义HASHTABLE,链表等结构来实现动态的数组 但在java中,已经有现成的,称为集合 Collection (interface,有迭代器)├List (interface)│├LinkedList (class)│├ArrayLis...
分类:
编程语言 时间:
2014-06-15 13:12:19
阅读次数:
210
背景
由于某种原因,我们系统需要记录另一个系统中一个表里的id。
但是,当我们记录完了以后,别人系统可能会删除那个表里的一些数据,这样的话,我们这边就多了一些无效数据,所以,我们必须的找到这些无效的id,然后将其删除。
开始,我们的实现是这样:我们将记录下来的所有id放在一个list里,然后传到另一个系统,他将他们已经删除的id返回。具体处理代码如下:
public String f...
分类:
其他好文 时间:
2014-06-14 15:06:57
阅读次数:
234