Strdata – TsingleLinkedList

package Ayo_SingleLink;

/**
*
* @author Nurul Collection
*/
public class Tsimpul {
private String kode;
private String nama;
private int info;
private Tsimpul next;

public Tsimpul(int info){
this.info=info;
this.next=null;
}

public void setkode(String kode){
this.setKode(kode);
}
public String getKode() {
return kode;
}

public void setNama(String nama) {
this.nama = nama;
}
public String getNama() {
return nama;
}

public void setinfo(int info){
this.info=info;
}
public int getinfo(){
return this.info;
}

public void setnext(Tsimpul next){
this.next=next;
}
public Tsimpul getnext(){
return this.next;
}

public void setKode(String kode) {
this.kode = kode;
}
}

 

________________________________—–_____—–______——_________________________________

 

package Ayo_SingleLink;

/**
*
* @author MSI
*/
public class coba_tsll {

private Tsimpul awal;
private Tsimpul akhir;

public void tsll(){
awal=null;
akhir=null;
}
public void Tambah_diAwal(Tsimpul baru){
if(awal==null){   // status kosong
akhir=baru;
}
else{
baru.setnext(awal); // status terisi
}
awal=baru;
}
public Tsimpul Ambil_diAwal (){
Tsimpul R = awal;
if(R!=null){
awal=awal.getnext();
if(awal==null){
akhir=null;
}
R.setnext(null);
}
return R;
}
public void Tambah_diAkhir(Tsimpul baru){
if(akhir==null){
awal=baru;
}
else{
akhir.setnext(baru);
}
akhir=baru;
}
public Tsimpul Ambil_diAkhir(){
Tsimpul R = akhir;
if(R!=null){
if(awal==akhir){
awal=null;
akhir=null;
}else {
Tsimpul RT = awal;
while (RT.getnext()!=akhir){
RT = RT.getnext();
}
RT.setnext(null);
akhir=RT;
}
}return R;
}
public void Tambah_diTengah(Tsimpul Ref, Tsimpul baru){
if(Ref!=null){
if(Ref==akhir){
Tambah_diAkhir(baru);
}
else{
baru.setnext(Ref.getnext());
Ref.setnext(baru);
}
}else{
Tambah_diAwal(baru);
}
}
public void Ambil_diTengah(Tsimpul Ref){
Tsimpul R=null;
if(Ref!=null){
R=Ref.getnext();
Ref.setnext(R.getnext());
R.setnext(null);
if(R==akhir){
akhir=Ref;
}
}

}
//return R;

public void print() {
Tsimpul ts = awal;
while (ts!=null) {
System.out.println(ts.getinfo());
ts = ts.getnext();
}
}
}

________________________________—–_____—–______——_________________________________

package Ayo_SingleLink;

//import javax.swing.JOptionPane;

/**
*
* @author MSI
*/
public class Ayo_panggil {
public static void main(String[] args) {
System.out.println(“Data yang belum diambil : “);
Tsimpul n;
coba_tsll tsll = new coba_tsll();

n = new Tsimpul(2);
tsll.Tambah_diAwal(n);
n = new Tsimpul(1);
tsll.Tambah_diAwal(n);
n = new Tsimpul(1);

n = new Tsimpul(3);
tsll.Tambah_diAkhir(n);
tsll.print();
System.out.println();

n = tsll.Ambil_diAkhir();
System.out.print(“Data yang diambil diakhir : “);
System.out.println(n.getinfo()+”\nMaka sisa”);
tsll.print();
System.out.println();
n = tsll.Ambil_diAwal();
System.out.print(“Data yang diambil diawal : “);
System.out.println(n.getinfo()+”\nJadi sisa”);
tsll.print();
}
}

package Ayo_SingleLink;

//import javax.swing.JOptionPane;

/**
*
* @author MSI
*/
public class Ayo_panggil {
public static void main(String[] args) {
System.out.println(“Data yang belum diambil : “);
Tsimpul n;
coba_tsll tsll = new coba_tsll();

n = new Tsimpul(2);
tsll.Tambah_diAwal(n);
n = new Tsimpul(1);
tsll.Tambah_diAwal(n);
n = new Tsimpul(1);

n = new Tsimpul(3);
tsll.Tambah_diAkhir(n);
tsll.print();
System.out.println();

n = tsll.Ambil_diAkhir();
System.out.print(“Data yang diambil diakhir : “);
System.out.println(n.getinfo()+”\nMaka sisa”);
tsll.print();
System.out.println();
n = tsll.Ambil_diAwal();
System.out.print(“Data yang diambil diawal : “);
System.out.println(n.getinfo()+”\nJadi sisa”);
tsll.print();
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s