Java 基于链表的队列创建
来源:互联网 发布:施工网络计划图软件 编辑:程序博客网 时间:2024/05/29 13:40
队列先进先出,因此此处采用尾插法进行链表创建,同时需要标记head ,tail
public class List { int content; List next; public List(int content,List next){ this.content=content; this.next=next; } public static List insert(List list,int context){ return new List(context,list); }}
上面的代码是创建链表的过程
package base;import java.util.Scanner;public class Queue { List head; List tail; public Queue(){ this.head=null; this.tail=head; } public void pop(int context){ if(this.head==null){ this.head=List.insert(this.head, context); this.tail=this.head; } else{ List temp=List.insert(null, context); this.tail.next=temp; this.tail=this.tail.next; } } public int pull(){ if(this.head==null){ System.out.println("队列已经为空"); return -1; } else{ int context=this.head.content; this.head=this.head.next; return context; } } public static void main(String[] args) {//基于链表的队列实现; // TODO Auto-generated method stub Queue qu=new Queue(); Scanner input =new Scanner(System.in); String number=input.nextLine(); while(!number.equals("end")){ qu.pop(Integer.parseInt(number)); number=input.nextLine(); } System.out.println("队列进入完毕"); while(qu.head!=null){ System.out.println(qu.pull()); } }}
0 0
- Java 基于链表的队列创建
- java基于有序链表的优先级队列实现
- 基于Java的消息队列
- 基于链表的栈和队列
- 基于链表的队列实现
- C语言基于链表的队列
- 基于链表的队列实现
- 链表创建队列
- 基于数组的循环队列和基于链表的队列
- 队列基于链表和数组的实现方法(java)
- 基于单链表的链队列
- java 基于数组实现的队列
- 基于链表实现Java 自定义Queue队列
- Java算法系列3--基于链表自定义队列
- 基于链表实现队列
- 典型数据结构--基于链表的队列实现
- 简单队列的实现(基于链表)
- 基于数组和链表的队列实现
- python 处理pascal voc数据 读取xml文件
- CMD中编译器和调试器的常用命令
- Java中的集合存储数据后,输出数据的有序和无序问题
- 微信小程序之仿淘宝分类入口 —— 微信小程序实战商城系列(2)
- 基于《PythonCookbook》的学习(2)——在字符串的卡头或结尾做文本匹配
- Java 基于链表的队列创建
- CSDN日报20170414 ——《从菜鸟到架构师》
- 面向对象分析与设计实验:在线购物
- Android build.gradle写法
- oracle2
- 第三章 多态
- http协议及ajax原理
- PHPmailer发送邮件SMTP Error:Could not authenticate
- request请求转发相关知识点