LAPORAN PRAKTIKUM LINKED LIST
Disusn Oleh :
Riski Yoga Kusumadya
201101019
Dosen :
Yosef Murya Kusuma Ardhana, S.T
JURUSAN SISTEM INFORMASI
SEKOLAH TINGGI ILMU KOMPUTER (STIKom)
"YOS SUDARSO"
PURWOKERTO
2012
=========================================================================
LISTING PROGRAM 6.1 BORLAN DAN ECLIPSE
BORLAND
#include <iostream.h>
#include <alloc.h>
#include <conio.h>
void 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;
}
getche();
}
OUTPUT PROGRAM
ECLIPSE
//============================================================================
// Name : linked1.cpp
// Author :
// 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;
}
OUTPUT PROGRAM
LISTING PROGRAM 6.2 BORLAND DAN ECLIPSE
BORLAND
#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;
}
OUTPOT PROGRAM
ECLIPSE
#include <iostream>
#include <stdlib.h>
#include <malloc.h>
//#include <conio.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
LISTING PROGRAM 6.3 BORLAND DAN ECLIPSE
BORLAND
#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;
}
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
ECLIPSE
#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
Tidak ada komentar:
Posting Komentar