Program Linked List Tambah Depan

Program Linked List Tambah Depan

Bagi teman2 yang butuh SourcoCode Program Linked List Tambah Depan dan Tampil Depan dengan bahasa Java disini ada tapi disini memakai Jeliot.
Berikut SourcoCodenya:



<br />
import jeliot.io.*;</p>
<p>class Link{<br />
      public int Data;<br />
      public Link next;</p>
<p>      public Link(int a){<br />
             Data = a;<br />
      }</p>
<p>      public void displayLink(){<br />
             System.out.print(&quot;[&quot;+Data+&quot;] &quot;);<br />
      }<br />
}</p>
<p>class LinkList{<br />
      private Link first;</p>
<p>      public LinkList(){<br />
             first = null;<br />
      }</p>
<p>      public void insertFirst(int a){<br />
              Link newLink = new Link(a);<br />
              newLink.next = first;<br />
              first = newLink;<br />
      }</p>
<p>      public void displayList(){<br />
             System.out.print(&quot;List (Awal ==&amp;gt; Akhir): &quot;);<br />
             Link isidata = first;<br />
             while(isidata != null){<br />
                   isidata.displayLink();<br />
                   isidata = isidata.next;<br />
             }<br />
             System.out.println(&quot;&quot;);<br />
     }<br />
}</p>
<p>class LinkListApp{<br />
      public static void main(){<br />
             int pil=0;<br />
             LinkList theList = new LinkList();<br />
             while(pil !=3){<br />
                  System.out.println(&quot;1. Tambah Data&quot;);<br />
                  System.out.println(&quot;2. Tampilkan List&quot;);<br />
                  System.out.println(&quot;3. Exit&quot;);<br />
                  System.out.print(&quot;Masukkan Pilihan: &quot;);pil=Input.readInt();<br />
                  if(pil==1){<br />
                     int isi=Input.readInt();<br />
                     theList.insertFirst(isi);<br />
                  }<br />
                  else if(pil==2){<br />
                      theList.displayList();<br />
                  }<br />
                  else{<br />
                      System.out.println(&quot;Pilihan tidak ada&quot;);<br />
                  }<br />
             }<br />
     }<br />
}<br />

Share