如题,主要考虑执行效率如果只有一个元素,不删除
如果全都是相同元素,保留一个节点
其他情况,删除所有最小元素节点
如果全都是相同元素,保留一个节点
其他情况,删除所有最小元素节点
解决方案 »
- spring mvc jsp页面显示问题
- jlist 怎么使用
- 大家快快帮忙啊
- try catch finally的问题
- 英雄会 XX采药 挑战失败,由于程序运行总时间大于3s导致超时
- 请问大家用java编写网络蚂蚁需要用到哪些知识阿
- another 100分
- about executeBatch()
- ========FreeJava编译能通过,但不能运行,why?=======
- 为何出现这个错误:java.sql.SQLException: 对只读结果集的无效操作: updateString;code如下:
- SWT中的System.out.println()的打印到富文本框中的问题
- 如何求一个int型数的绝对值?
public class LinkNode
{
private int data;
private LinkNode next;
private LinkList list;
public LinkNode(LinkList list)
{
this.list=list;
}public LinkNode(int data)
{
this.data=data;
}
public void setNext(LinkNode next)
{
this.next=next;
}public LinkNode getNext()
{
return this.next;
}
public void setData(int data)
{
this.data=data;
}
public int getData()
{
return data;
}
}public class AlgNode
{
LinkNode node;
LinkNode previousNode;public AlgNode(LinkNode node,LinkNode preNode)
{
this.node=node;
this.previousNode=preNode;
}public LinkNode getNode()
{
return this.node;
}public LinkNode getPreNode()
{
return previousNode;
}
}
public class LinkList
{private LinkNode head;
private LinkNode tailNode;
private int size=0;
// private LinkNode currentNode = null;
public LinkList(LinkNode head)
{
this.head=head;
tailNode=head;
}public LinkList()
{
head = new LinkNode(this);
head.setNext(null);
this.tailNode=head;
}public void setSize(int size)
{
this.size=size;
}//删除第一个元素
public void delete()
{
if(head.getNext()!=null)
{
this.head.setNext(head.getNext().getNext());
this.size--;
}
else
this.tailNode=head;
}//在当前节点之后插入新节点
public void append(int data)
{
LinkNode node = new LinkNode(data);
this.tailNode.setNext(node);
tailNode = node;
this.size++;
}public LinkNode getTailNode()
{
return tailNode;
}public int getSize()
{
return this.size;
}public LinkNode getHead()
{
return this.head;
}// public boolean delete(LinkNode node)
// {
//
// return false;
// }
}public class Main {/**
* @param args
*/
public static void main(String[] args)
{
LinkList linkList = new LinkList();
linkList.append(2);
linkList.append(2);
linkList.append(2);
linkList.append(2);
linkList.append(3);
linkList.append(1);
linkList.append(5);LinkNode head = linkList.getHead();
LinkNode currNode = head.getNext();
LinkNode preNode = head;
List<AlgNode> list = new ArrayList<AlgNode>();
int minval=currNode.getData();while(currNode!=null)
{
if(minval>currNode.getData())
{
minval=currNode.getData();
list.clear();
AlgNode node = new AlgNode (currNode,preNode);
list.add(node);
}
else if(minval==currNode.getData())
{
AlgNode node = new AlgNode (currNode,preNode);
list.add(node);
}
preNode = currNode;
currNode=currNode.getNext();
}AlgNode algNode = null;
for(int i=list.size()-1;i>=0&&linkList.getSize()>1;i--)
{
algNode=list.get(i);
LinkNode pnode=algNode.getPreNode();
LinkNode node = algNode.getNode();
pnode.setNext(node.getNext());
linkList.setSize(linkList.getSize()-1);
}currNode = head.getNext();
while(currNode!=null)
{
System.out.print(currNode.getData()+" ");
currNode = currNode.getNext();
}
}}
String comm = "perl /var/www/extsuite/extman/tools/userctl.pl--mod=add -username="+uname +"-password="+pass;
runLinuxCmd(String cmd) //本类调用public String runLinuxCmd(String cmd) {
BufferedReader bf = null;
try {
Process process = Runtime.getRuntime().exec(cmd);
bf = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
String resutl="";
while ((line = bf.readLine()) != null) {
resutl =resutl+ line.trim()+"\n";
}
System.out.println("---------------try result------------------"+resutl);
return resutl;
} catch (java.io.IOException e) {
e.printStackTrace();
System.out.println("------------error--------------");
return null;
} finally {
if (bf != null) {
try {
bf.close();
bf = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}}单独在shell环境下执行perl命令是没有问题,能够插入数据。 我在网上看到有人讲过把perl命令写进sh脚本就可以了,我也不知道这是为什么按理说java能够调用shell命令也能调用perl脚本命令。非要包装一下的话我也写了一个shell脚本单独运行shell脚本也能添加数据就是java调用又没有添加数据了 我想要的是验证过的结果 大道理就不用讲了直接来真工夫啊 我写的shell脚本代码如下:#!/bin/sh
perl /var/www/extsuite/extman/tools/userctl.pl--mod=add -username="$1" -password="$2";这个做了两天都没有做好 如果能有满意的结果我会加分的谢谢大家 欢迎大家来这里回帖http://topic.csdn.net/u/20110821/20/ae1e4815-1c81-4c75-88ae-db263128f963.html?61772
Object data; Node next; Node(Object d) {
data = d;
next = null;
}
}public class LinkList { /* 用变量来实现表头 */
private Node Head = null; private Node Tail = null; private Node Pointer = null; //point to previous private int Length = 0; public void deleteAll() {// 清空整个链表
Head = null;
Tail = null;
Pointer = null;
Length = 0;
} // 链表复位,使第一个节点成为当前节点
public void reset() {
Pointer = null;
} // 判断链表是否为空
public boolean isEmpty() {
return (Length == 0);
} // 判断当前结点是否为最后一个结点
public boolean isEnd() {
if (Length == 0)
throw new java.lang.NullPointerException();
else if (Length == 1)
return true;
else
return (cursor() == Tail);
} // 返回当前结点的下一个结点的值,并使其成为当前结点
public Object nextNode() {
if (Length == 1)
throw new java.util.NoSuchElementException();
else if (Length == 0)
throw new java.lang.NullPointerException();
else {
Node temp = cursor();
Pointer = temp;
if (temp != Tail)
return (temp.next.data);
else
throw new java.util.NoSuchElementException();
}
} // 返回当前结点的值
public Object currentNode() {
Node temp = cursor();
return temp.data;
} // 在当前结点前插入一个结点,并使其成为当前结点
public void insert(Object obj) {
Node e = new Node(obj);
if (Length == 0) {
Tail = e;
Head = e;
} else {
Node temp = cursor();
e.next = temp;
if (Pointer == null)
Head = e;
else
Pointer.next = e;
}
Length++;
} // 返回链表的大小
public int size() {
return Length;
} // 将当前结点移出链表,下一个结点成为当前结点,
// 如果移出的结点是最后一个结点,
// 则第一个结点成为当前结点
public Object remove() {
Object temp;
if (Length == 0)
throw new java.util.NoSuchElementException();
else if (Length == 1) {
temp = Head.data;
deleteAll();
} else {
Node cur = cursor();
temp = cur.data;
if (cur == Head)
Head = cur.next;
else if (cur == Tail) {
Pointer.next = null;
reset();
} else
Pointer.next = cur.next;
Length--;
}
return temp;
} // 返回当前结点的指针
private Node cursor() {
if (Head == null)
throw new java.lang.NullPointerException();
else if (Pointer == null)
return Head;
else
return Pointer.next;
} // 链表的简单应用举例
public static void main(String[] args) {
LinkList a = new LinkList();
for (int i = 1; i <= 10; i++)
a.insert(new Integer(i));
System.out.println("The currentNode is:" + a.currentNode());
while (!a.isEnd())
System.out.println("The nextNode is:" + a.nextNode());
a.reset();
while (!a.isEnd()) {
a.remove();
}
a.remove();
a.reset();
if (a.isEmpty()) {
System.out.println("There is no Node in List");
}
}
}