Data structure of the queue Java version

Source: Internet
Author: User

Java is very inconvenient to use because of the generic erase

Abstract classBasequeue<t>{    AbstractBoolean enQueue (T x); AbstractT front (t x);//Note that There's a difference between this and C + +, which directly returns the header element    AbstractBoolean Delqueue (); Abstract voidClear ();}classQueue<t> extends Basequeue<t>{    intmmaxsize,mindexf,mindexr;    T []mqueue; @SuppressWarnings ("unchecked") Queue (Class<T> type,intMaxSize) {mmaxsize=maxSize; MINDEXF=mindexr=0; Mqueue=(t[]) array.newinstance (type, maxSize); } @Override Boolean EnQueue (T x) {//TODO auto-generated Method Stub        if(isfull ()) {//over Flow            return false; }Else{MINDEXF= (mindexf+1)%mmaxsize; mqueue[mindexf]=x; return true; }} @Override T Front (t x) {//TODO auto-generated Method Stub        if(isEmpty ()) {//Emprty            return NULL; }        Else{x=mqueue[mindexf]; System. out. println (x); returnx; }} @Override Boolean delqueue () {//TODO auto-generated Method Stub        if(isEmpty ()) {//Empty            return false; }        Else{MINDEXR= (mindexr+1)%mmaxsize; return true; }} @OverridevoidClear () {//TODO auto-generated Method StubMindexf=mindexr=0; } Boolean isfull () {if((mindexr+1)%mmaxsize==Mindexr) {            return true; }Else{            return false; }} Boolean isEmpty () {returnmindexf==mindexr; }} public classJbqueue { public Static voidmain (String Args[]) {Integer J=6; Queue<Integer> test=NewQueue<> (Integer.class,Ten); Test.enqueue (3); Test.front (j);//the value of J is not changed as a result of the eraseSystem. out. println (test.front (j)); }    Static intffintJ) {j--; returnj; }}

Data structure of the queue Java version

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.