NIM : 201101004
Program Linked List 6.1 Nang Borlan
#include <stdio.h>
#include <conio.h>
#include <alloc.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)
{
printf("%d",node->number);
node=node->next;
}
getche();
}
Output Programnya
Program Linked List 6.2 Nang Borlan
#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 telmlist *alamat;
typedef struct telmlist
{
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<<" Masukkan Banyak data = ";
cin>>k;
for (i=1;i<=k;i++)
{
cout<<" Masukkan Data Senarai ke-"<<i<<" = ";
cin>>nilai;
n=nodbaru(nilai);
sisipsenarai (&pel,n,NULL);
}
cetaksenarai(pel);
getch();
return 0;
}
Output Programnya
Program Linked List 6.3 Nang Borlan
#include <string.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
class node
{
public:
int z;
node *next;
};
void main ()
{
clrscr ();
int n,i;
node*awal,*akhir,*temp;
awal=new node;
akhir=awal;
cout<<"Masukan Datanya Bro =";
cin>>n;
for(i=1;i<=n;++i)
{
temp=new node;
temp->next=NULL;
cout<<"data"<<i<<"=";
cin>>temp->z;
akhir->next=temp;
akhir=temp;
}
cout<<"seluruh data\n";
temp=awal->next;
while(temp->next!=NULL)
{
cout<<temp->z<<endl;
temp=temp->next;
}
while(temp!=NULL)
{
cout<<temp->z<<endl;
temp=temp->next;
}
int posisi;
cout<<"Diapus posisi ke";
cin>>posisi;
node*temp1,*temp2;
temp1=awal;
for (i=1;i<posisi;++i)
temp1=temp1->next;
temp2=temp1->next;
temp1->next=temp2->next;
delete temp2;
cout<<"Kabehan Data \n";
temp=awal->next;
while (temp!=NULL)
{
cout<<temp->z<<endl;
temp=temp->next;
}
getche ();
}
Output Programnya
Program Linked List 6.1 Eclipse
//================================================
// Name : 1.cpp
// Author : Gatra Mustakim
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//================================================
#include <iostream>
#include <malloc.h>
#include <list>
using namespace std;
int main(int)
{
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 Programnya
Program Linked List 6.2 Eclipse
//==================================================
// Name : 2.cpp
// Author : Gatra Mustakim
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//===================================================
#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 telmlist *alamat;
typedef struct telmlist
{
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<<" Masukkan Banyak data = ";
cin>>k;
for (i=1;i<=k;i++)
{
cout<<" Masukkan Data Senarai ke-"<<i<<" = ";
cin>>nilai;
n=nodbaru(nilai);
sisipsenarai (&pel,n,NULL);
}
cetaksenarai(pel);
getche();
return 0;
}
Output Programnya
Program Linked List 6.3 Eclipse
//============================================================================
// Name : 3.cpp
// Author : Gatra Mustakim
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <string.h>
#include <conio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
class node
{
public:
int z;
node *next;
};
int main ()
{
int n,i;
node*awal,*akhir,*temp;
awal=new node;
akhir=awal;
cout<<"Masukan Datanya Bro =";
cin>>n;
for(i=1;i<=n;++i)
{
temp=new node;
temp->next=NULL;
cout<<"data"<<i<<"=";
cin>>temp->z;
akhir->next=temp;
akhir=temp;
}
cout<<"seluruh data\n";
temp=awal->next;
while(temp->next!=NULL)
{
cout<<temp->z<<endl;
temp=temp->next;
}
while(temp!=NULL)
{
cout<<temp->z<<endl;
temp=temp->next;
}
int posisi;
cout<<"Diapus posisi ke";
cin>>posisi;
node*temp1,*temp2;
temp1=awal;
for (i=1;i<posisi;++i)
temp1=temp1->next;
temp2=temp1->next;
temp1->next=temp2->next;
delete temp2;
cout<<"Kabehan Data \n";
temp=awal->next;
while (temp!=NULL)
{
cout<<temp->z<<endl;
temp=temp->next;
}
getche ();
}
Output Programnya