Donny Davis wrote:im sorry for my misconduct....
but one thing can you explain me what does these line of code mean
can a stack program be sortable.... if yes then the logic of LIFO is nowhere....
and what does that E stand for???
The E is the generic element type. If you would have an ISortableStack<String> it would only be able to handle Strings, and an ISortableStack<Integer> would only be able to handle Integers.
The stack doesn't need to be sortable - its elements should be. If you read more closely, the extends Comparable<E> applies to E. Therefore, you can create an ISortableStack<String> (because String implements Comparable<String>), but not an ISortableStack<InputStream>, or even an ISortableStack<java.sql.Timestap>. InputStream doesn't even implement Comparable, and java.sql.Timestamp does not implement Comparable<java.sql.Timestamp> but Comparable<java.util.Date> instead (through inheritance).
As for the LIFO logic - ISortableStacks can only be modified by using pop() and push(), making it behave like a regular LIFO stack. The sortable only applies to the read-only methods peekMidElement(), peekHighestElement() and peekLowestElement().
The E indicates a generic type. Oracle has quite a detailed tutorial on using generics, which is quite a big topic. The short answer is that E stands for some type that is unknown at the moment but will be specified when the class is created. That way you can have a stack of Strings, or a stack of anything else you want.
In terms of sorting: it looks to me as if it's supposed to behave like a common stack, but with convenience methods for finding the highest and lowest values.
Not a big deal... As you see, when you asked a specific question, you got lots of help.
Welcome to the Ranch!
Joined: Aug 24, 2011
hey guys thankx for your replies
so i will make a class named stack....
it will implement an interface named Isortable stack
im planning to use an array
for the code <<E extends comparable<<E>> i will write code for comparing integers and that too in methods for the highest n the lowest ones
and pop and push will just insert and remove elements from the stack.....
peekmidelement will return the middle element
How do i write the code for enqueue, deque functions...please just point me to a solution and i'll try to code the same
Welcome to ranch.
As for your post , fred already said that we do not do homework for you. I would suggest you to read your Datastructure well. The logic of a queue is very realistic, I am sure you'd enjoy it. I am also posting a link for you