daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Mylist{
  2.     String [] list;
  3.     public Mylist(){
  4.         String []list;
  5.     }
  6.     public Mylist(String s){
  7.         list=new String[1];
  8.         list[0]=s;
  9.     }
  10.     public Mylist(String []s){
  11.         list=s;
  12.     }
  13.     public int Length(){
  14.         return list.length;
  15.     }
  16.     public String First(){
  17.         return this.list[0];
  18.     }
  19.     public String[] Rest(){
  20.         list[0]="";
  21.         return list;
  22.     }
  23.     public void Insert(String n, int j){
  24.         list[j]=n;
  25.     }
  26.     public void Delete(String e){
  27.         for(int k=0;k<list.length;k++){
  28.             if(list[k]==e){
  29.                 list[k]="";
  30.             }
  31.         }
  32.     }
  33.     public boolean isEmpty(){
  34.         if(list != null){
  35.             return false;
  36.         }
  37.         else return true;
  38.     }
  39.     public boolean subList(String[]f){
  40.         int l=0;
  41.         int m=0;
  42.         while (m<list.length && l<f.length){
  43.             if(f[l].equals(list[m])){
  44.                 l++;
  45.             }
  46.             m++;
  47.         }
  48.         if(l==f.length){
  49.             return true;
  50.         }
  51.         else return false;
  52.     }
  53. //now for testing the code
  54.     public static void main (String[] args) {
  55.         Mylist l1=new Mylist();
  56.         Mylist l2=new Mylist("Ali");
  57.         String [] trail={"ali","ahmad","mohamed","mostafa","ali","hetham","said","ali"};
  58.         Mylist l3=new Mylist(trail);
  59.         System.out.println("the length of trail is "+l3.Length());
  60.         System.out.println("the first name in trail is "+l3.First());
  61.         System.out.print("while the rest are " );
  62.         String[]reast=l3.Rest();
  63.         for(int x=0;x<reast.length;x++){
  64.             System.out.print(reast[x]+ " ");
  65.         }
  66.         System.out.println("the first and only name in list 2 is "+ l2.First());
  67.         l2.Insert("shafee2 :)",0);
  68.         System.out.println("which after changing became "+l2.First());
  69.         l3.Delete("ali");
  70.         System.out.print("list 3 after purifying it from ali is "+l3.First());
  71.         String[]loot=l3.Rest();
  72.         for(int y=0;y<loot.length;y++){
  73.             System.out.print(loot[y]+ " ");
  74.         }
  75.         System.out.println("whoever said list 1 is empty was "+l1.isEmpty());
  76.         String []finale={"ahmad","mohamed","said"};
  77.         System.out.println("the final question is if given list is substring of L3, the answer is " +l3.subList(finale));
  78.     }
  79.     //done...
  80. }
RAW Paste Data
Top