面试题 一个序列顺序为{0,1,2.......N}节点定义如下?public void Node(){String value;Node next;}怎样让他的顺序倒置过来;{n,n-1.......0}那位高手指点一下本人对数据结构不是很熟啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上班临时写的,测试通过,没有考虑效率public class C { public static void main(String []args) { int l = args.length ; int [] a = new int[l] ; int temp ; for(int i=0;i<l;i++) { a[i] = Integer.parseInt(args[i]) ; } for(int i=0;i<=(a.length/2 -1);i++) { temp = a[i] ; a[i] = a[l-i-1] ; a[l-i-1] = temp ; } for(int i=0;i<l;i++) { System.out.println(a[i]); } }} C:\>javac C.javaC:\>java C 1 2 3 4输入的顺序是: 1 2 3 4倒序后的结果是: 4 3 2 1 public static Node g(Node head) { Node previous = null; Node current = head; while (current != null) { Node next = current.next; current.next = previous; previous = current; current = next; } return previous; } public class Test{ /** * @param args */ public static void main(String[] args) { List<Integer> l1=new ArrayList<Integer>(); l1.add(1); l1.add(2); l1.add(3); l1.add(4); l1.add(5); l1.add(6); l1.add(7); l1.add(8); l1.add(9); l1.add(10); Collections.reverse(l1); Node pre=null; Node newNode=null; Node nodeHead=null; for(int i=0;i<l1.size();i++){ if(pre!=null){ newNode=new Node(); newNode.setValue(l1.get(i)); pre.setNext(newNode); pre=newNode; }else{ pre=new Node(); pre.setValue(l1.get(i)); nodeHead=pre; } } pre=nodeHead; while(pre!=null){ System.out.println(pre.getValue()); pre=pre.getNext(); } } }class Node{ private int value; private Node next; public Node(int arg0,Node next){ this.value=arg0; this.next=next; } public Node(){ } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; } public int getValue() { return value; } public void setValue(int value) { this.value = value; }} 咨询一问题:httpclient 多线程如何监控页面是否改变呢? 《JAVA编程思想》中第四章第二题的答案错了。 为什么启动不了tomcat??? 帮忙解释一下接口的耦合,完全耦合,接藕,看书不大懂~ java对象还原问题 关于实参中的null????? 算法问题~~ 连接sql的问题,提示的错误::在线等啊 【非官方北京地面活动】近期准备在车库咖啡搞一次自学JAVA的同学会,讨论讨论学习过程中遇到的问题 关于JAVA继承 java 数组和字符串有什么区别? GBK 转 UTF-8问题
public class C {
public static void main(String []args) {
int l = args.length ;
int [] a = new int[l] ;
int temp ;
for(int i=0;i<l;i++) {
a[i] = Integer.parseInt(args[i]) ;
}
for(int i=0;i<=(a.length/2 -1);i++) {
temp = a[i] ;
a[i] = a[l-i-1] ;
a[l-i-1] = temp ;
}
for(int i=0;i<l;i++) {
System.out.println(a[i]);
}
}
}
输入的顺序是:
1 2 3 4
倒序后的结果是:
4 3 2 1
public static Node g(Node head) {
Node previous = null;
Node current = head;
while (current != null) {
Node next = current.next;
current.next = previous;
previous = current;
current = next;
}
return previous;
}
public class Test{ /**
* @param args
*/
public static void main(String[] args) {
List<Integer> l1=new ArrayList<Integer>();
l1.add(1);
l1.add(2);
l1.add(3);
l1.add(4);
l1.add(5);
l1.add(6);
l1.add(7);
l1.add(8);
l1.add(9);
l1.add(10);
Collections.reverse(l1);
Node pre=null;
Node newNode=null;
Node nodeHead=null;
for(int i=0;i<l1.size();i++){
if(pre!=null){
newNode=new Node();
newNode.setValue(l1.get(i));
pre.setNext(newNode);
pre=newNode;
}else{
pre=new Node();
pre.setValue(l1.get(i));
nodeHead=pre;
}
}
pre=nodeHead;
while(pre!=null){
System.out.println(pre.getValue());
pre=pre.getNext();
}
}
}
class Node{
private int value;
private Node next;
public Node(int arg0,Node next){
this.value=arg0;
this.next=next;
}
public Node(){
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}