• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Double-ended queue java source code or c++ source code

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to look at double-ended queue implementation.
Any one who know the double-ended queue implementation can give the source code or the link.
I understand the double-ended queue. I just want to look at the source code. I want to to know how the complete double-ended queue is designed.
Thanks for any help.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a java.util.Deque interface, which has a few implementations. You could check the sources, but the JDK implementation is probably not as simple as you could imagine.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find the source code for classes in the JDK, such as java.util.Deque, in the file src.zip which is in your JDK installation directory.
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christophe Thanks.
the java.util.Queue may be too complicated for me. I just want to know some necessary member for Dequeue.
So I post my Dequeue.java source code .
Thanks for any suggestions for the below Dequeue.java code.

 
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You ought to make the method names correspond to the names in the Deque interface. The names push and pop are usually applied to stacks, not queues, although you find the Deque interface can be used as a stack.
You have a class with instance fields in; you need to initialise that in the constructor. Then you can forget about the != null tests. If the array is null, then it is impossible for your class to perform any functionality at all. Your code to increase the size of the array is duplicated; it should be moved into a private method for resizing the capacity.
Your pop methods should throw an EmptyStackException when you have a size of 0, rather than returning -1. What happens if you push -1 onto your stack?
Your pop methods leave an unused reference on the stack. They should be implemented more like thisThis is more important with reference types; you need to set them to null, not 0, otherwise there is a risk of a memory leak.
 
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Your pop methods should throw an EmptyStackException when you have a size of 0, rather than returning -1.


That should be java.util.NoSuchElementException
 
Campbell Ritchie
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, all right then, NoSuchElement.
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much.
 
Campbell Ritchie
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
This tiny ad is guaranteed to be gluten free.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic