stack implementation using data abstraction(very urgent)

Data abstraction -- mutable

Implement Stack data abstraction that provides following public methods to its clients:

1. push(Object a)
2. pop()
3. top()
4. peek(int depth)

Since the stack allows a client to store any object, use the following instance variables:

1. private Object [] elements
2. private int size = 0

Because we are using an array to store objects, provide a constructor that allocates sufficient memory desired by the client, i.e.,
public Stack(int initialCapacity)
In addition, when the size of the stack is equal to initial capacity, allocate more memory (i.e., increase the size of the array. In other words, create a new array of twice the size and copy all stored elements into it). Since the size has to be checked every time you call push method, you should create a private method that does this for you. As an example, you could use the following signature:
private void ensureCapacity()

peek(int depth) looks ahead and reports the element stored at the specified depth. It is possible to call this method with depth greater than the stack's current capacity -- an erroneous call. Hence, it has to be properly documented (total procedure) informing the client of incorrect invocations. An interesting implementation would use push, top, pop with a Stack object, i.e., pop depth-1 number of elements and push them into an accompanying stack. Report the top element at this stage. Finally empty the accompanying stack and push all the elements back into the original stack. Try to implement this method using this scheme (you are not required to do so). You are required to specify the data abstraction completely. Note that pop(), top() and peek() can be called on an empty stack and push() called with a null argument.

Comments

  • : Data abstraction -- mutable
    :
    : Implement Stack data abstraction that provides following public methods to its clients:
    :
    : 1. push(Object a)
    : 2. pop()
    : 3. top()
    : 4. peek(int depth)
    :
    : Since the stack allows a client to store any object, use the following instance variables:
    :
    : 1. private Object [] elements
    : 2. private int size = 0
    :
    : Because we are using an array to store objects, provide a constructor that allocates sufficient memory desired by the client, i.e.,
    : public Stack(int initialCapacity)
    : In addition, when the size of the stack is equal to initial capacity, allocate more memory (i.e., increase the size of the array. In other words, create a new array of twice the size and copy all stored elements into it). Since the size has to be checked every time you call push method, you should create a private method that does this for you. As an example, you could use the following signature:
    : private void ensureCapacity()
    :
    : peek(int depth) looks ahead and reports the element stored at the specified depth. It is possible to call this method with depth greater than the stack's current capacity -- an erroneous call. Hence, it has to be properly documented (total procedure) informing the client of incorrect invocations. An interesting implementation would use push, top, pop with a Stack object, i.e., pop depth-1 number of elements and push them into an accompanying stack. Report the top element at this stage. Finally empty the accompanying stack and push all the elements back into the original stack. Try to implement this method using this scheme (you are not required to do so). You are required to specify the data abstraction completely. Note that pop(), top() and peek() can be called on an empty stack and push() called with a null argument.
    :
    I will write it, if you write for me a multi-threaded binary tree implementation.
  • : : Data abstraction -- mutable
    : :
    : : Implement Stack data abstraction that provides following public methods to its clients:
    : :
    : : 1. push(Object a)
    : : 2. pop()
    : : 3. top()
    : : 4. peek(int depth)
    : :
    : : Since the stack allows a client to store any object, use the following instance variables:
    : :
    : : 1. private Object [] elements
    : : 2. private int size = 0
    : :
    : : Because we are using an array to store objects, provide a constructor that allocates sufficient memory desired by the client, i.e.,
    : : public Stack(int initialCapacity)
    : : In addition, when the size of the stack is equal to initial capacity, allocate more memory (i.e., increase the size of the array. In other words, create a new array of twice the size and copy all stored elements into it). Since the size has to be checked every time you call push method, you should create a private method that does this for you. As an example, you could use the following signature:
    : : private void ensureCapacity()
    : :
    : : peek(int depth) looks ahead and reports the element stored at the specified depth. It is possible to call this method with depth greater than the stack's current capacity -- an erroneous call. Hence, it has to be properly documented (total procedure) informing the client of incorrect invocations. An interesting implementation would use push, top, pop with a Stack object, i.e., pop depth-1 number of elements and push them into an accompanying stack. Report the top element at this stage. Finally empty the accompanying stack and push all the elements back into the original stack. Try to implement this method using this scheme (you are not required to do so). You are required to specify the data abstraction completely. Note that pop(), top() and peek() can be called on an empty stack and push() called with a null argument.
    : :
    : I will write it, if you write for me a multi-threaded binary tree implementation.
    :
    haa sorry .... i have totally no programming knowledge, that is why im requesting for the solution for this program.... so if u can please help me out
  • : : : Data abstraction -- mutable
    : : :
    : : : Implement Stack data abstraction that provides following public methods to its clients:
    : : :
    : : : 1. push(Object a)
    : : : 2. pop()
    : : : 3. top()
    : : : 4. peek(int depth)
    : : :
    : : : Since the stack allows a client to store any object, use the following instance variables:
    : : :
    : : : 1. private Object [] elements
    : : : 2. private int size = 0
    : : :
    : : : Because we are using an array to store objects, provide a constructor that allocates sufficient memory desired by the client, i.e.,
    : : : public Stack(int initialCapacity)
    : : : In addition, when the size of the stack is equal to initial capacity, allocate more memory (i.e., increase the size of the array. In other words, create a new array of twice the size and copy all stored elements into it). Since the size has to be checked every time you call push method, you should create a private method that does this for you. As an example, you could use the following signature:
    : : : private void ensureCapacity()
    : : :
    : : : peek(int depth) looks ahead and reports the element stored at the specified depth. It is possible to call this method with depth greater than the stack's current capacity -- an erroneous call. Hence, it has to be properly documented (total procedure) informing the client of incorrect invocations. An interesting implementation would use push, top, pop with a Stack object, i.e., pop depth-1 number of elements and push them into an accompanying stack. Report the top element at this stage. Finally empty the accompanying stack and push all the elements back into the original stack. Try to implement this method using this scheme (you are not required to do so). You are required to specify the data abstraction completely. Note that pop(), top() and peek() can be called on an empty stack and push() called with a null argument.
    : : :
    : : I will write it, if you write for me a multi-threaded binary tree implementation.
    : :
    : haa sorry .... i have totally no programming knowledge, that is why im requesting for the solution for this program.... so if u can please help me out
    :
    Since programming knowledge is best gained by trial-and-error, and not by letting others do your work for you, you should post some code and show us what you've done so far.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories