Queue with a single-linked list with a tail-up node

Source: Internet
Author: User
Package Db;public class Queue<e> {/** * Inner class--Single linked list * @author Fightzhao * * @param <E> */private static class Nod e<e> {public node<e> next;public e data;public Node (e data, node<e> next) {This.data = Data;this.next = Next;}} Private node<e> front;private node<e> rear;private int thesize;/** * enqueued * @param data */public void Enqueue (E  Data) {node<e> Pnode = new node<e> (data, NULL), if (rear! = null) {Rear.next = Pnode;rear = Pnode;} else {front = Rear = Pnode;} thesize++;} public int size () {return thesize;} /** * Out team * @return */public e dequeue () {e data = front.data;if (Front.next! = null) {front = Front.next;} else {front = R ear = null;} Thesize--;return data;} Public Queue () {front = Null;rear = null;} public void printall () {node<e> pnode= front;while (pnode!=null) {System.out.println (pnode.data);p node= Pnode.next;}}}

  

Queue with a single-linked list with a tail-up node

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.