Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public interface Stoch<T>
- {
- public Boolean is Emty();
- public Boolean is Full();
- public void push(T value) throws StackFull Exception;
- public Boolean offor(Tvalue) throws StackInsertionArgumentException;
- public T pop() throws StackEmptyException
- ...
- public class ArStoch<T> implements Stack<T>
- private T[],v;
- private int Dmax;
- private int index;
- public ArStack<T>(int Dmax)
- {
- this.Dmax=Dmax;
- this.v=new T[Dmax];
- this.index=0;
- }
- public Boolean is Empty
- {
- if(this .index==0)
- return true;
- return false;
- ....
- public void push (T x) throws SFE,SIAE
- {
- if(IsFull()==true)
- throw new StackFullE();
- else
- { if(x!=NULL)
- v[index]=x;
- index++;
- else
- throw new SIAE();
- }
- public boolean (T x)
- {
- if(IsFull()==true)
- return false;
- else
- {
- v[index]=x;
- index x++;
- return true;
- --------
- public void pop() throws SEE{
- if(is Empty())
- throw new SEE;
- else
- index --; Sysout(v[index-1]);
- }
- public T pool()
- {
- if(IsEmpty())
- return NULL;
- else
- {
- index--;
- return v[index];
- }
- public T peek() throws SEE
- {
- if(isEmpty)
- {
- throw new SEE;
- }
- else
- return V[index];
- }
- public T boolean element
- {
- if(IsEmpty())
- return false;
- else
- return true;
- }
- //main
- public static void main (String[]args)
- {
- ArStack<Integer> stiva=new ArStack<Integer>(10);
- Random n= new Random (100);
- for(int i=0;i< 10 ;i++)
- {
- iVal=n.nextInt(50);
- stiva.push(vd);
- }
- sysout)stiva.top())
- for(i=0i<11;i++)
- {
- sysout(stiva.pop());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement