|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2003
Città: Costiera Amalfitana
Messaggi: 604
|
[JAVA]: costruttore di Object per STACK
Dato il seguente codice che crea uno stack con una lista linkata:
public class LinkedStack implements stack{ public LinkedStack(){ top = null; size = 0; } public LinkedStack(Object[] A){ } public int size(){ return size; } public boolean isEmpty(){ if(top==null) return true; return false; } public Object push(Object elem){ Node v = new Node(); v.setElement(elem); v.setNext(top); top = v; size++; return elem; } public Object top() throws StackEmptyException{ if(isEmpty()) throw new StackEmptyException ("Stack vuoto"); return top.getElement(); } public Object pop() throws StackEmptyException{ if(isEmpty()) throw new StackEmptyException("Stack vuoto"); Object temp = top.getElement(); top = top.getNext(); size--; return temp; } private Node top; private int size; } devo creare un costruttore che mi prende in input un array di Object e mi inizializzi lo stack con gli elementi dell'array (il primo elemento da inserire nello stack è A[0], il secondo A[1], ...). Chi mi aiuta a creare questo costruttore??? public LinkedStack(Object[] A){ } GRAZIE.
__________________
C A R P E D I E M |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 02:25.



















