本文实例讲述了Java数据结构之有效队列定义与用法。分享给大家供大家参考,具体如下:public class SequeQueue { private long[] arr; private int maxSize;// 最大空间 priv
本文实例讲述了Java数据结构之有效队列定义与用法。分享给大家供大家参考,具体如下:
public class SequeQueue { private long[] arr; private int maxSize;// 最大空间 private int len;// 有效长度 public SequeQueue(int size) { this.maxSize = size; this.arr = new long[maxSize]; this.len = 0; } public void insert(long value) { int i; for (i = 0; i < len; i++) { //得到i if (value > arr[i]) { break; } } //移动数据,把前面的数据往后移动一位 for (int j = len; j > i; j--) { arr[j] = arr[j - 1]; } arr[i] = value; len ++; } public long remove() { long value = arr[len - 1]; len --; return value; } public boolean isEmpty() { return (len == 0); } public boolean isFull() { return (len == maxSize); } public int size() { return len; } public static void main(String[] args) { SequeQueue queue = new SequeQueue(8); queue.insert(22); queue.insert(33); queue.insert(44); queue.insert(534); queue.insert(21); queue.insert(55); System.out.println("编程网测试结果:"); while (!queue.isEmpty()) { System.out.println(queue.remove()); } }}
--结束END--
本文标题: Java数据结构之有效队列定义与用法示例
本文链接: https://www.lsjlt.com/news/222147.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0