Modul 6 : Linked List
Disusun Oleh:
Kristianus Unang
201101018
Dosen Pengampu:
Yosef Murya Kusuma Ardhana, S.T
Jurusan Sistem Informasi
Sekolah Tinggi Ilmu Komputer (STIKOM)
"Yos Sudarso"
Purwokerto
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Laporan Praktikum 6.1 (borland edition)
script
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
main()
{
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;
}
getche();
}
#include<conio.h>
#include<alloc.h>
main()
{
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;
}
getche();
}
screenshot program
6.1 |
Laporan Praktikum 6.1 (eclipse edition)
script
//============================================================================
// Name : linked_list.cpp
// Author : unang
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#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;
}
screenshoot program
6.1 |
---------------------------------------------------------------------------------------------------------------------------------------
LAPORAN PRAKTIKUM 6.2 (borland edition)
script
#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;
int 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;
}
}
int sisipsenarai (list *L,list t,list p)
{
if (p==nil)
{
t->next=*L;
*L=t;
}
else
{
t->next=p->next;
p->next=t;
}
}
int 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;
}
#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;
int 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;
}
}
int sisipsenarai (list *L,list t,list p)
{
if (p==nil)
{
t->next=*L;
*L=t;
}
else
{
t->next=p->next;
p->next=t;
}
}
int 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;
}
screenshoot program
6.2 |
LAPORAN PRAKTIKUM 6.2(eclipse edition)
script
//============================================================================
// Name : link_list.cpp
// Author : unang
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#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);
return 0;
}
// Name : link_list.cpp
// Author : unang
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#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);
return 0;
}
screenshoot program
LAPORAN PRAKTIKUM 6.3
script
#include <string.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
class node
{
public:
int x;
node *next;
};
int main ()
{
int n,i;
node*awal,*akhir,*temp;
awal=new node;
akhir=awal;
cout<<"Masukkan 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<<"seluruh 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<<"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 ();
}
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
class node
{
public:
int x;
node *next;
};
int main ()
{
int n,i;
node*awal,*akhir,*temp;
awal=new node;
akhir=awal;
cout<<"Masukkan 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<<"seluruh 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<<"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 ();
}
screenshoot program
6.3 |
LAPORAN PRAKTIKUM(eclipse edition)
script
//============================================================================
// Name : linkk_list.cpp
// Author : unang
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#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<<"Masukkan 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;
}
// Name : linkk_list.cpp
// Author : unang
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#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<<"Masukkan 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;
}
screenshoot program
6.3 |
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Tidak ada komentar:
Posting Komentar