Kamis, 26 Mei 2016

Link List

#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
struct TNode{
char nim[15];
char nama[30];
int usia;
TNode *next;
};
TNode *head;
int opsi = 0;
void init(){
head = NULL;
}
bool isEmpty(){
if (head ==NULL) return true;
else return false;
}
void add_at_front(){
TNode *baru;
baru = new TNode;
cout << "Masukkan NIM         : ";
cin >> baru-> nim;
cout << "Masukkan Nama        : ";
cin >> baru-> nama;
cout << "Masukkan Usia anda   : ";
cin >> baru-> usia;
baru->next = NULL;
system("CLS");
if(isEmpty()==true){
head=baru;
head->next = NULL;
}else {
baru->next = head;
head = baru;
}
}
void add_at_end(){
TNode *baru,*bantu;
baru = new TNode;
cout << "Masukkan NIM               : ";
cin >> baru-> nim;
cout << "Masukkan Nama              : ";
cin >> baru-> nama;
cout << "Masukkan Usia anda         : ";
cin >> baru-> usia;
baru->next = NULL;
system("CLS");
if(isEmpty()== true){
head=baru;
head->next = NULL;
} else {
bantu=head;
while(bantu->next!=NULL){
bantu=bantu->next;
}
bantu->next = baru;
}
}
void add_at_midle(){
TNode *baru, *bantu;
int posisiSisip;
if(isEmpty()== false){
cout<<"Akan disisip setelah Data Ke ? : "; cin>>posisiSisip;
bantu=head;
baru=new TNode;
for(int i=1;i<posisiSisip;i++){
if(bantu->next!=NULL)
bantu=bantu->next;
else break;
}
cout << "Masukkan NIM          : ";
cin >> baru-> nim;
cout << "Masukkan Nama         : ";
cin >> baru-> nama;
cout << "Masukkan Usia anda    : ";
cin >> baru-> usia;
baru->next=bantu->next;
bantu->next=baru;
system("CLS");
}
else cout<<"Mau sisip tengah Belum ada data !! …silahkan masukkan Data dula aja…..";
}
void del_at_front () {
TNode *hapus;
if (isEmpty() == false){
if(head->next !=NULL){
hapus = head;
head = head->next;
delete hapus;
system("CLS");
} else {
head = NULL;
}
}else {
cout<<"Data anda masih kosong !!!!n";
}
}
void del_at_end(){
TNode *hapus, *bantu;
if (isEmpty()==false){
if(head->next !=NULL){
bantu = head;
while(bantu->next->next!=NULL){
bantu = bantu->next;
}
hapus = bantu->next;
bantu->next = NULL;
delete hapus;
system("CLS");
} else {
head = NULL;
}
} else {
cout<<"Data anda masih kosong !!!!n";
}
}
void del_at_midle(){
int banyakdata,posisiSisip,poshapus;
TNode *hapus, *bantu;
if(isEmpty()== false){
cout<<"Akan dihapus pada data ke : "; cin>>posisiSisip;
banyakdata=1;
bantu=head;
while(bantu->next!=NULL)
{
bantu=bantu->next;
banyakdata++;
}
if((posisiSisip<1)||(posisiSisip>banyakdata)){
cout<<"Belum ada data !! …silahkan masukkan Data dula aja…..n";
}else {
bantu=head;
poshapus=1;
while(poshapus<(posisiSisip-1))
{
bantu=bantu->next;
poshapus++;
}
hapus=bantu->next;
bantu->next=hapus->next;
delete hapus;
system("CLS");
}
}
else cout<<"Data Masih kosong, tidak bisa hapus data dari tengah! ";
}
void display_list(){
    int i=0;
system("CLS");
TNode *bantu;
bantu = head;
if(isEmpty()==true){
cout<<"Data masih kosong\n";
} else {
cout<<endl<<"DATA DOUBLE LINKED LIST\n";
while(bantu!=NULL){
        i++;
cout<<">"<<i<<"\t NIM    : " << bantu->nim << "\n";
cout<<"\t NAMA   : " << bantu->nama<< "\n";
cout<<"\t USIA   : " << bantu->usia<< "\n";
cout<<"---------------------------------";
cout<<endl;
bantu=bantu->next;


}
cout<<endl;
}
}
int main(){
int();
do{
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"-:: MENU PILIHAN::-"   <<endl;
cout<<endl;
cout<<"1. Tambah Simpul dari Depan."   <<endl;
cout<<"2. Tambah Simpul dari Belakang."   <<endl;
cout<<"3. Tambah Simpul dari Tengah."  <<endl;
cout<<"4. Hapus Simpul dari Depan."  <<endl;
cout<<"5. Hapus Simpul dari Belakang."   <<endl;
cout<<"6. Hapus Simpul dari Tengah."  <<endl;
cout<<"7. Tampil Data."   <<endl;
cout<<"8. Keluar."  <<endl;
cout<<endl;
cout<< "Pilihan Menu : ";
cin >> opsi;
switch(opsi){
case 1 : add_at_front();break;
case 2 : add_at_end();break;
case 3 : add_at_midle();break;
case 4 : del_at_front();break;
case 5 : del_at_end();break;
case 6 : del_at_midle();break;
case 7 : display_list();break;
}
}while (opsi != 8);
}

Minggu, 01 Mei 2016

Buble Sort an Insertion Sort


                           1. Bubble Sort           
                  a. Pengertian Bubble Sort
Bubble Sort adalah salah satu algoritma untuk sorting data, atau kata lainnya mengurutkan data dari yang terbesar ke yang terkecil atau sebaliknya (Ascending atau Descending).

Tugas Struktur Data

1.Pengertian  Interpolation Search 

Interpolation Search adalah sebuah algoritma atau metode untuk mencari nilai key yang diberikan dalam array diindeks yang telah diperintahkan oleh nilai – nilai kunci.