Advertisement
Adytzu04

l2 tema1 Java

Mar 23rd, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. Public interface Stoch<T>
  2. {  
  3.     public Boolean is Emty();
  4.     public Boolean is Full();
  5.     public void push(T value) throws StackFull Exception;
  6.     public Boolean offor(Tvalue) throws StackInsertionArgumentException;
  7.     public T pop() throws StackEmptyException
  8.  
  9. ...
  10.  
  11.     public class ArStoch<T> implements Stack<T>
  12.     private T[],v;
  13.     private int Dmax;
  14.     private int index;
  15.    
  16.     public ArStack<T>(int Dmax)
  17. {  
  18.     this.Dmax=Dmax;
  19.     this.v=new T[Dmax];
  20.     this.index=0;
  21. }
  22.  
  23.     public Boolean is Empty
  24. {
  25.     if(this .index==0)
  26.     return true;
  27. return false;
  28.  
  29. ....
  30.  
  31.     public void push (T x) throws SFE,SIAE
  32. {
  33.     if(IsFull()==true)
  34.     throw new StackFullE();
  35.     else
  36.     {   if(x!=NULL)
  37.         v[index]=x;
  38.     index++;
  39.     else
  40. throw new SIAE();
  41. }
  42.  
  43. public boolean (T x)
  44. {
  45.     if(IsFull()==true)
  46. return false;
  47. else
  48. {
  49.     v[index]=x;
  50. index  x++;
  51.     return true;
  52.  
  53. --------
  54.  
  55. public void pop() throws SEE{
  56. if(is Empty())
  57. throw new SEE;
  58. else
  59. index --; Sysout(v[index-1]);
  60. }
  61. public T pool()
  62. {
  63.     if(IsEmpty())
  64.     return NULL;
  65.     else
  66. {  
  67.     index--;
  68.     return v[index];
  69. }
  70.  
  71. public T peek() throws SEE
  72. {  
  73.     if(isEmpty)
  74.     {
  75.         throw new SEE;
  76.      }
  77. else
  78. return V[index];
  79. }
  80.  
  81. public T boolean element
  82. {
  83.  if(IsEmpty())
  84.     return false;
  85.    
  86.     else
  87. return true;
  88. }
  89.  
  90.            
  91. //main
  92.  
  93. public static void main (String[]args)
  94. {
  95. ArStack<Integer> stiva=new ArStack<Integer>(10);
  96. Random n= new Random (100);
  97.  
  98. for(int i=0;i<  10  ;i++)
  99. {
  100.     iVal=n.nextInt(50);
  101.     stiva.push(vd);
  102. }
  103. sysout)stiva.top())
  104. for(i=0i<11;i++)
  105. {
  106.  sysout(stiva.pop());
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement