1. Setelah deklarasi node dilakukan, dan semua fungsi sudah tersedia. Sekarang gabungkan
setiap fungsi yang ada pada sebuah program penuh dengan spesifikasi:
➢ Pada program utama (main) berisi sebuah menu yang bersifat fitur-fitur yang
terdapat dari setiap fungsi yang sudah ada sebelumnya, yaitu: tambahan data, hapus
data, cek data kosong, cetak semua data.
➢ Pada struct hanya terdapat 1 tipe data saja yaitu integer.
➢ Sesuaikan fungsi-fungsi yang ada dengan program yang anda buat (jangan langsung
copy-paste dan digunakan.
a. Source Code
#include <iostream>
#include <stdio.h>
#include <iomanip>
long data;
node* next; //tipe data bertipe sama untuk menunjuk ke node lain
node* prev;
};
node* head;
node* tail;
node* print;
node* del;
node* entry;
void inisialisasi()
head = NULL;
tail = NULL;
int isEmpty()
if(head == NULL)
return 1;
else
return 0;
entry->data = *dta;
entry->next = NULL;
entry->prev = NULL;
if(isEmpty()==1)
head = entry;
head->next = NULL;
head->prev = NULL;
tail=head;
else
tail->next = entry;
entry->prev = tail;
tail = entry;
}
//penghapusan data di belakang melalui head
void hapus()
int simpan;
if(head!=NULL) //jika hanya kondisi ini saja maka akan terjadi error karena ada syntax head-
>prev = NULL
if(head->next != NULL)
del=head;
simpan = head->data;
head = head->next;
delete del;
else
simpan = head->data;
head = NULL;
else
cout << "\nLinked List kosong penghapusan tidak dapat dilakukan " <<endl;
print = head;
if(head!=NULL)
while(print!=NULL)
{
print = print->next;
else
cout << "\nTidak ada data dalam linked list" <<endl; //jika data sudah kosong
void menu()
int data;
do
system("clear");
menu :
switch(pilih)
case '1' :
break;
case '2' :
hapus();
break;
case '3' :
cetak();
break;
case '4' :
exit;
break;
default :
goto menu;
int main()
inisialisasi();
menu();
return 0;
b. Deskripsi code
typedef struct node Deklarasi Node :
{ Node*next sebagai tipe data bertipe sama
untuk menunjukkan ke node lain.
long data;
node* prev;
};
if(head == NULL)
return 1;
else
return 0;
entry->data = *dta;
entry->next = NULL;
entry->prev = NULL;
if(isEmpty()==1)
head = entry;
head->next = NULL;
head->prev = NULL;
tail=head;
else
tail->next = entry;
entry->prev = tail;
tail = entry;
}
}
int simpan;
if(head->next != NULL)
del=head;
simpan = head->data;
head = head->next;
delete del;
else
simpan = head->data;
head = NULL;
else
void cetak() //menampilkan semua data Untuk menampilkan semua data yang telah
{ ditambahkan.
print = head;
if(head!=NULL)
while(print!=NULL)
print = print->next;
else
head = NULL;
tail = NULL;
c. Screenshot
2. Buat program untuk enkripsi dan deskripsi password yang memanfaatkan linked list, dengan
spesifikasi :
• Panjang password min 6 digit.
• Isi password terserah dari user dan password di inputkan terlebih dahulu sebelumnya
(penambahan data di belakang).
• Enkripsi dilakukan dengan memindahkan 3 node terakhir menjadi node terdepan.
Kemudian sisipkan 1 karakter baru (kunci) setelah node ketiga dari yang di pindahkan
tsb.
• Ilustrasi
a. Source Code
#include <iostream>
#include <string.h>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
struct node{
char data;
}*head, *tail;
void init()
head = NULL;
bool isEmpty ()
if (head == NULL)
return true;
else
return false;
node *baru;
if (isEmpty())
head = baru;
tail = baru;
} else {
head = baru;
node *baru;
if ( isEmpty())
head = baru;
tail = baru;
} else {
tail = baru;
void deleteDepan()
node *hapus;
if(isEmpty())
} else {
hapus = head;
} else {
head = NULL;
void deleteBelakang ()
node *hapus;
if (isEmpty())
} else {
hapus = tail;
delete hapus;
} else {
head = NULL;
void cetak ()
if (isEmpty())
{
} else {
insertDepan(key);
deleteBelakang();
insertDepan(arrayy[i]);
deleteDepan();
insertBelakang(arrayy[i]);
int main()
init();
int pil;
menu :
switch (pil)
case 1 :
jumlah = strlen(password);
n = 0;
if (jumlah < 6)
system("pause");
system("cls");
goto menu;
} else {
insertBelakang(password[i]);
simpan[n] = password[i];
n++;
kunci = '@';
enkripsi(kunci,simpan);
cetak();
system("pause");
system("cls");
goto menu;
break;
case 2 :
jumlah = strlen(password);
n = 0;
if (jumlah < 6)
system("pause");
system("cls");
goto menu;
} else {
insertBelakang(password[i]);
simpan[n] = password[i];
n++;
dekripsi(simpan);
cetak();
system("pause");
system("cls");
goto menu;
break;
case 3 :
system("exit");
return 0;
b. Deskripsi code
}*head, *tail;
head = NULL;
{
if (head == NULL)
return true;
else
return false;
head = baru;
tail = baru;
{
Head harus barada di depan
head = baru;
tail = baru;
} else {
tail = baru;
node *hapus;
} else {
Jika data masih lebih dari Saturday
if (head ->next != NULL)
{
Letakkan hapus pada head
hapus = head;
head = head -> next; Menggeser head, karena head harus di
depan
head -> prev = NULL;
head menuju ke NULL
delete hapus; proses delete tidak boleh dilakukan jika
node masih ditunjuk oleh pointer
} else { jika data tinggal head
head = NULL; langsung diberi nilai NULL saja
node *hapus;
} else {
Jika data masih lebih dari satu
if (head -> next != NULL)
{
Menghubungkan node akhir
hapus = tail;
delete hapus;
} else {
head = NULL;
if (isEmpty())
} else {
cout << bantu -> data; Cetak data pada setiap node
c. Screenshot