链表-j-优先级队列,单向链表实现
来源:互联网 发布:pythonpath linux 编辑:程序博客网 时间:2024/06/12 22:50
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();
}
}
/**
* 优先级队列,单向链表实现
*
* @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
- 链表-j-优先级队列,单向链表实现
- 单向队列和优先级队列
- 用单向链表实现队列功能
- C++模板链表实现优先级队列
- 顺序表实现优先级队列
- 一个单向链表,并实现栈和队列
- java基于有序链表的优先级队列实现
- 用链表实现优先级队列
- 优先级队列实现
- 优先级队列的实现
- Java优先级队列实现
- c#实现优先级队列
- 优先级队列的实现
- 1.5 实现优先级队列
- 自己动手实现优先级队列
- java实现优先级队列
- Python优先级队列实现
- 单向链表实现
- 链表-H-双向链表,允许前后遍历
- 高质量的SRS的一些特性
- 链表-I-链表实现迭代器
- MySQL数据库的子查询
- 常见中外出版社
- 链表-j-优先级队列,单向链表实现
- Python-opencv学习
- 链表-K-链表实现 双端队列
- Python学习之日志模块详解
- Windows Server2003本地用户的批量导入和导出
- 链表-L-循环链表
- 基于机器学习的网络异常流量识别系统——工具篇
- 504. Base 7
- SpringMVC入门之六:使用Thymeleaf作为视图