Advertisement
Guest User

Dictionary

a guest
Feb 7th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. public class Dictionary
  2. {
  3.     private int max;
  4.     private String[] liste;
  5.  
  6.     public Dictionary()
  7.     {
  8.         liste = new String[100];
  9.         max = 0;
  10.     }
  11.  
  12.     public void insert(String x)
  13.     {
  14.         if(member(x) == false)
  15.         {
  16.             liste[max] = x;
  17.             max ++;
  18.         }
  19.         else
  20.         {
  21.             System.out.println("Der String '" +x+ "' ist bereits im Dictionary vorhanden!");
  22.         }
  23.     }
  24.  
  25.     public void delete(String x)
  26.     {
  27.         int i = 0;
  28.         boolean gefunden = false;
  29.         while (i < max && gefunden == false)
  30.         {
  31.             if(liste[i] == x)
  32.             {
  33.                 gefunden = true;
  34.                 for(int h = i; h<max;h++)
  35.                 {
  36.                     liste[h] = liste[h+1];
  37.                 }
  38.                 max--;
  39.             }
  40.             i++;
  41.         }
  42.     }
  43.  
  44.     public boolean member(String x)
  45.     {
  46.         int i = 0;
  47.         boolean gefunden = false;
  48.         while (i < max && gefunden == false)
  49.         {
  50.             if(liste[i] == x)
  51.             {
  52.                 gefunden = true;
  53.             }
  54.             i++;
  55.         }
  56.         return gefunden;
  57.     }
  58.  
  59.     public boolean empty()
  60.     {
  61.         return max==0;
  62.     }
  63.  
  64.     public int length()
  65.     {
  66.         return max;
  67.     }
  68.  
  69.     public String anzeigen(int i)
  70.     {
  71.         return liste[i];
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement