链表-j-优先级队列,单向链表实现

package e_link.I_priorityQue;


/**
 * 优先级队列,单向链表实现
 * 
 * @author Administrator
 * 
 */
public class Demo {
public void fun1() {
QueueSort theQs = new QueueSort();
theQs.insert(15);
theQs.insert(25);
theQs.insert(97);
theQs.insert(6);
theQs.insert(7);
theQs.insert(79);
theQs.insert(32);
theQs.insert(66);
theQs.insert(1);
theQs.displayList();
System.out.println();
theQs.remove();
theQs.remove();
theQs.displayList();
}
}package e_link.I_priorityQue;


public class Link {
public int iData;
public Link next;


public Link(int iData) {
this.iData=iData;
}


public void display() {
System.out.print(iData + " ");
}
}package e_link.I_priorityQue;


public class LinkList {
private Link first;


public LinkList() {
first = null;
}


public int deleteMin() {
int temp = first.iData;
first = first.next;
return temp;
}


public void insert(int iData) {
Link newLink = new Link(iData);
Link current = first;
Link previous = null;
// 判断是否为空
while (current != null && current.iData < iData) {// 循环得到存放的位置
previous = current;
current = current.next;
}
if (previous != null)// 说明current在first后面
previous.next = newLink;
else
// 说明current就是first
first = newLink;
newLink.next = current;


}


public boolean isEmpty() {
return first == null;
}


public void displayLink() {
Link current = first;
while (current != null) {
current.display();
current = current.next;
}
}
}package e_link.I_priorityQue;


/**
 * 优先级队列链表实现
 * 
 * @author Administrator
 * 
 */
public class QueueSort {
private LinkList theLinkList;


public QueueSort() {
theLinkList = new LinkList();
}


public void insert(int i) {
theLinkList.insert(i);
}


public int remove() {
int temp = theLinkList.deleteMin();
return temp;
}


public void displayList() {
theLinkList.displayLink();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值