博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java学习之—链表(3)
阅读量:4676 次
发布时间:2019-06-09

本文共 1916 字,大约阅读时间需要 6 分钟。

/** * 使用链表实现队列 * Create by Administrator * 2018/6/19 0019 * 下午 4:37 **/public class Link {    public long dData;    public Link next;    public Link(long d){        this.dData = d;    }    public void displayLink(){        System.out.print(dData + " ");    }}class FirstLastList{    private Link first;    private Link last;    public FirstLastList(){        this.first = null;        this.last = null;    }    public boolean isEmpty(){        return first == null;    }    public void insertLast(long dd){        Link newLink = new Link(dd);        if(isEmpty()){            first = newLink;        }else {            last.next = newLink;        }        last = newLink;    }    public long deleteFirst(){        long temp = first.dData;        if(first.next == null){            last = null;        }        first = first.next;        return temp;    }    public void displayList(){        Link current = first;        while (current != null){            current.displayLink();            current = current.next;        }        System.out.println("");    }}class LinkQueue{    private FirstLastList theList;    public LinkQueue(){        this.theList = new FirstLastList();    }    public boolean isEmpty(){        return theList.isEmpty();    }    public void insert(long j){        theList.insertLast(j);    }    public long remove(){        return theList.deleteFirst();    }    public void displayQueue(){        System.out.print("Queue (front-->rear): ");        theList.displayList();    }    public static void main(String[] args) {        LinkQueue linkQueue = new LinkQueue();        linkQueue.insert(20);        linkQueue.insert(40);        linkQueue.displayQueue();        linkQueue.insert(60);        linkQueue.insert(80);        linkQueue.displayQueue();        linkQueue.remove();        linkQueue.remove();        linkQueue.displayQueue();    }}

  

 

转载于:https://www.cnblogs.com/chancy/p/9199391.html

你可能感兴趣的文章
1078. Hashing (25)-PAT甲级真题
查看>>
SQLite中的运算符表达式
查看>>
Grid使用 & ComboBox Binding & DateTime Format WPF
查看>>
.Net Core迁移到MSBuild的多平台编译问题
查看>>
数据结构之删除线性表中的元素
查看>>
redis安装配置
查看>>
结对项目博客
查看>>
讨论记录:求大于一个时间段的最大平均积分,O(n)时间实现
查看>>
error) DENIED Redis is running in protected mode because protected mode is enabled报错
查看>>
CSS-16-margin值重叠问题
查看>>
selenium常用方法
查看>>
第二次作业
查看>>
ios 面试题
查看>>
express细节点注意
查看>>
MySQL教程(二)—— 关于在ACCESS中使用SQL语句
查看>>
实验4.1
查看>>
接口Interface
查看>>
bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚【贪心+堆||差分】
查看>>
bzoj 1710: [Usaco2007 Open]Cheappal 廉价回文【区间dp】
查看>>
电商:购物车模块解决思路
查看>>