Minggu, 10 Juni 2012

Laporan Praktikum Modul 6 Linked List (Novian Adi P) (201101029)

Laporan Praktikum Modul 6 Linked List
Disusun oleh :
Novian Adi Prasetyo
201101029

Dosen
Yosef Murya Kusuma Ardhana, S.T


JURUSAN SISTEM INFORMASI
SEKOLAH TINGGI ILMU KOMPUTER (STIKOM)
“YOS SUDARSO”
PURWOKERTO
2012


                        ------------------------

Menggunakan Program Eclipse

>> Program 6.1


Listing Program :

#include <iostream>
#include <malloc.h>
#include <list>

using namespace std;
int main (void)
{
       int i;

       struct ListEntry
       {
              int number;
              struct ListEntry *next;
       } start, *node;

       start.next=NULL;
       node= &start;
       for (i=1;i<=10;i++)
       {
              node->next=(struct ListEntry *) malloc(sizeof(struct ListEntry));
              node=node->next;
              node->number=i;
              node->next=NULL;
       }
       node=start.next;

       while (node)
       {
              cout<<node->number<<" ";
              node=node->next;
       }
       return 0;
}
Output Program :



















>> Program 6.2


Listing Program :

#include <iostream>

#include <stdlib.h>

#include <malloc.h>





using namespace std;



#define nil NULL

#define info(P) P->info

#define next(P) P->next

#define first(L) (L)



typedef int infotype;

typedef struct telmtlist *alamat;

typedef struct telmtlist

{

       infotype info;

       alamat next;

} elmtlist;



typedef alamat list;



void buatsenarai(list *L)

{

       first (*L) = nil;

}

list nodbaru(int m)

{

       list n;

       n = (list) malloc(sizeof(elmtlist));

       if (n != NULL)

       {

              info (n) = m;

              next(n) = nil;

       }

       return n;

}

void sisipsenarai(list *L, list t, list p)

{

       if (p == nil)

       {

              t->next = *L;

              *L = t;

       } else {

              t->next = p->next;

              p->next = t;

       }

}

void cetaksenarai(list L)

{

       list ps;

       for (ps = L; ps != nil; ps = ps->next)

       {

              cout << " " << info(ps)<<" -->";

       }

       cout << " NULL" << endl;

}

int main()

{

       list pel;

       list n;

       int i, k, nilai;



       buatsenarai(&pel);

       cout << "Masukan Data Banyak Data = ";

       cin >> k;

       for (i = 1; i <= k; i++)

       {

              cout << "Masukan data Senarai ke-" << i << " = ";

              cin >> nilai;

              n = nodbaru(nilai);

              sisipsenarai(&pel, n, NULL);

       }

       cetaksenarai(pel);

       //getche ();

       return 0;

}


Output Program :
















>> Program 6.3


Listing Program :

#include <string>

#include <iostream>

#include <stdlib.h>



using namespace std;



class node

{

public:

       int x;

       node *next;

};

int main ()

{

      

       int n,i;

       node*awal,*akhir,*temp;

       awal=new node;

       akhir=awal;

       cout<<"input data = ";

       cin>>n;

       for(i=1;i<=n;++i)

       {

              temp=new node;

              temp->next=NULL;

              cout<<"data ke "<<i<<" = ";

              cin>>temp->x;

              akhir->next=temp;

              akhir=temp;

       }

       cout<<"\nseluruh data\n";

       temp=awal->next;

       while(temp->next!=NULL)

       {

              cout<<temp->x<<endl;

              temp=temp->next;

       }

       

       while(temp!=NULL)

       {

              cout<<temp->x<<endl;

              temp=temp->next;

       }

       int p;

       cout<<"\nHapus posisi data ke = ";

       cin>>p;

       node*temp1,*temp2;

       temp1=awal;

       for (i=1;i<p;++i)

              temp1=temp1->next;

       temp2=temp1->next;

       temp1->next=temp2->next;

       delete temp2;

       cout<<"\nSeluruh Data \n";

       temp=awal->next;

       while (temp!=NULL)

       {

              cout<<temp->x<<endl;

              temp=temp->next;

       }

       return 0;

      

}

Output Program :

















Menggunakan Program Borland

>> Program 6.1


Listing Program :


#include <iostream.h>

#include <conio.h>

#include <alloc.h>



void main (void)

{

       int i;



       struct ListEntry {

              int number;

              struct ListEntry *next;

       } start, *node;



       clrscr();

       start.next=NULL;

       node= &start;

       for (i=1;i<=10;i++)

       {

              node->next=(struct ListEntry *) malloc(sizeof(struct ListEntry));

              node=node->next;

              node->number=i;

              node->next=NULL;

       }

       node=start.next;



       while (node)

       {

              cout<<node->number;

              node=node->next;

       }

       getche ();

}

Output Program :
















>> Program 6.2


Listing Program :


#include <iostream.h>

#include <stdlib.h>

#include <malloc.h>

#include <conio.h>



#define nil NULL

#define info(P) P->info

#define next(P) P->next

#define first(L) (L)



typedef int infotype;

typedef struct telmtlist *alamat;

typedef struct telmtlist

{

       infotype info;

       alamat next;

}elmtlist;



typedef alamat list;



void buatsenarai (list *L)

{

       first (*L) = nil;

}

list nodbaru(int m)

{

       list n;

       n=(list) malloc(sizeof(elmtlist));

       if (n!=NULL)

       {

              info (n) = m;

              next(n) = nil;

       }

       return n;

}

void sisipsenarai (list *L,list t,list p)

{

       if (p==nil)

       {

              t->next=*L;

              *L=t;

       }

       else

       {

              t->next=p->next;

              p->next=t;

       }

}

void cetaksenarai (list L)

{

       list ps;

       for (ps=L; ps!=nil; ps=ps->next)

       {

              cout<<" "<<info(ps)<<" -->";

       }

       cout<<" NULL"<<endl;

}

int main ()

{

       list pel;

       list n;

       int i,k,nilai;



       buatsenarai (&pel);

       cout<<"Masukan Data Banyak Data = ";

       cin>>k;

       for (i=1;i<=k;i++)

       {

              cout<<"Masukan data Senarai ke-"<<i<<" = ";

              cin>>nilai;

              n=nodbaru(nilai);

              sisipsenarai (&pel,n,NULL);

       }

       cetaksenarai (pel);

       getche ();

       return 0;

}

Output Program :







>> Program 6.3


Listing Program :


#include <string.h>

#include <conio.h>

#include <iostream.h>

#include <stdlib.h>

class node

{

public:

       int x;

       node *next;

};

void main ()

{

       clrscr ();

       int n,i;

       node*awal,*akhir,*temp;

       awal=new node;

       akhir=awal;

       cout<<"input data=";

       cin>>n;

       for(i=1;i<=n;++i)

       {

              temp=new node;

              temp->next=NULL;

              cout<<"data"<<i<<"=";

              cin>>temp->x;

              akhir->next=temp;

              akhir=temp;

       }

       cout<<"seluruh data\n";

       temp=awal->next;

       while(temp->next!=NULL)

       {

              cout<<temp->x<<endl;

              temp=temp->next;

       }

       //cout<<temp->x<<endl;

       //cout<<"seluruh data2\n";

       //temp=awal->next;

       while(temp!=NULL)

       {

              cout<<temp->x<<endl;

              temp=temp->next;

       }

       int p;

       cout<<"Hapus posisi ke";

       cin>>p;

       node*temp1,*temp2;

       temp1=awal;

       for (i=1;i<p;++i)

              temp1=temp1->next;

       temp2=temp1->next;

       temp1->next=temp2->next;

       delete temp2;

       cout<<"Seluruh Data \n";

       temp=awal->next;

       while (temp!=NULL)

       {

              cout<<temp->x<<endl;

              temp=temp->next;

       }

       getche ();

}

Output Program :


Tidak ada komentar:

Posting Komentar