CARA MERAKIT KOMPUTER DAN GAMBARNYA LENGKAP

Berikut ini akan dibahas mengenai bagaimana cara merakit komputer, terutama bagi mereka yang baru belajar. Dari beberepa referensi yang saya pelajari [Read More...]

SIMULASI INSTALLASI DEBIAN MENGGUNAKAN VIRTUALBOX

Berikut ini merupakan simulasi cara installasi debian menggunakan virtualbox, antara lain [Read More...]

KECANGGIHAN KONSEP KOMPUTER PENA MASA DEPAN

Anda ingin tahu lebih lengkap tentang konsep komputer masa depan ini?? Temukan jawaban dari penasaran anda mengenai Kecanggihan Konsep Komputer Masa Depan [Read More...]

DOORBOT: BEL PINTU DENGAN KAMERA YANG PUNYA KONEKSI WI-FI

Punya bel pintu dan ketika ada yang ngebel, anda berlari cepat dari kamar mandi dan tahu-tahunya cuma tukang jualan bakso atau parahnya lagi penagih hutang. Kesal kan? [Read More...]

8 RESEP MENGOPTIMALKAN WEBSITE ANDA

Punya website atau webblog? Anda berniat membangun website baru? Tapi tidak memiliki sumber daya yang cukup untuk membayar seorang desainer web handal atau konsultan? [Read More...]

Contoh Program Double Linked List

#include <iostream.h>
#include <conio.h>

struct node
{
node *pre;
char no_pel[20];
char name[20];
int gol;
int biaya_pasang;
int biaya_admin;
node *nxt;
};

node *head = NULL;
node *tail = NULL;

node *current,*previous;
int option = 0;

void add_node_at_end()
{ node *temp; // Temporary pointers

// Reserve space for new node and fill it with data
temp = new node;

temp->pre = NULL;
cout << "No Pelanggan : "; cin >> temp->no_pel;
cout << "Nama : "; cin >> temp->name;
cout << "Gol : "; cin >> temp->gol;
cout << "Biaya Pasang : "; cin >> temp->biaya_pasang;
cout << "Biaya Admin : "; cin >> temp->biaya_admin;
temp->nxt = NULL;

// Set up link to this node
if (head == NULL)
{
head = temp;
tail = temp;
current = head;
}
else
{
tail->nxt = temp;
temp->pre = tail;
tail = temp;
}
}

void display_list01()
{
node *temp, *temp1;
temp = head;
int total,i;
if (temp == NULL)
cout << endl << "The list is empty!" << endl;
else
{
//cetak judul
clrscr();
cout << "==================================================================" << endl;
cout << " No No Pel Nama Gol Biaya Pasang Biaya Admin Total " << endl;
cout << "==================================================================" << endl;
i=0;
do
{
i++;
// Display details for what temp points to
cout << i <<"\t";
cout << temp->no_pel << "\t";
cout << temp->name << "\t";
cout << temp->gol<< "\t";
cout << temp->biaya_pasang<< "\t";
cout << temp->biaya_admin<< "\t";
total=temp->biaya_pasang + temp->biaya_admin;
cout <<total<< "\t";
if (temp == current)
cout << " <-- Cur Node";
cout << endl;

temp1 = temp;
temp = temp->nxt;

} while (temp1 != tail);
cout << "==================================================================" << endl;
cout << "End of list!" << endl;
}
}

void display_list02()
{
node *temp, *temp1;
temp = tail;
int total,i;
if (temp == NULL)
cout << endl << "The list is empty!" << endl;
else
{
//cetak judul
clrscr();
cout << "==================================================================" << endl;
cout << " No No Pel Nama Gol Biaya Pasang Biaya Admin Total " << endl;
cout << "==================================================================" << endl;
i=0;
do
{
i++;
// Display details for what temp points to
cout << i <<"\t";
cout << temp->no_pel << "\t";
cout << temp->name << "\t";
cout << temp->gol<< "\t";
cout << temp->biaya_pasang<< "\t";
cout << temp->biaya_admin<< "\t";
total=temp->biaya_pasang + temp->biaya_admin;
cout <<total<< "\t";
if (temp == current)
cout << " <-- Cur Node";
cout << endl;

temp1 = temp;
temp = temp->pre;

} while (temp1 != head);
cout << "==================================================================" << endl;
cout << "End of list!" << endl;
}
}

void move_current_on ()
{
if(head==NULL)
{
// cout<<"Empty Linked list.."<<endl;
}
else
{
if (current->nxt == NULL)
{
cout << "You are at the end of the list." << endl;
}
else
{
current = current->nxt;
}
}
display_list01;
}

void move_current_back ()
{
if (current == head)
{
cout << "You are at the start of the list" << endl;
}
else
{
node *previous; // Declare the pointer
previous = head;
while (previous->nxt != current)
{
previous = previous->nxt;
}
current = previous;
}
}

void hapus_current()
{
node *temp, *temp_pre, *temp_nxt;
if(head==NULL)
{
cout<<"Masih Kosong Bro.."<<endl;
}
else
{
temp=current;
if(temp->pre!=NULL && temp->nxt!=NULL)
{
temp_pre=temp->pre;
temp_nxt=temp->nxt;
temp_pre->nxt=temp_nxt;
temp_nxt->pre=temp_pre;
current=temp_nxt;
}
else if(temp->pre!=NULL && temp->nxt==NULL)
{
current=head;
tail=temp->pre;
}
else if(temp->pre==NULL && temp->nxt==NULL)
{
current=temp->nxt;
}
else
{
current==NULL;
head=NULL;
tail=NULL;
}
delete temp;
}
}

//program utama..........................................
void main()
{ head= NULL;
do
{
cout << endl;
cout << "Please select an option : " << endl;
cout << "0. Exit the program." << endl;
cout << "1. Tambah di belakang." << endl;
cout << "2. Tampilkan dari depan." << endl;
cout << "3. Tampilkan dari belakang" << endl;
cout << "4. Current Cursor Up" << endl;
cout << "5. Current Cursor Down" << endl;
cout << "6. Hapus Current" << endl;
cout << endl << "Pilihan Anda ? ";cin >> option;

switch (option)
{
case 1 : add_node_at_end(); break;
case 2 : display_list01(); break;
case 3 : display_list02(); break;
case 4 : move_current_back();break;
case 5 : move_current_on(); break;
case 6 : hapus_current(); break;

}
} while (option != 0);
}