/* Single Linked List Non Circullar author: Didik Kurniawan */ #include <iostream> #include <stdlib.h> using namespace std; struct Data { int nilai; char nama[100]; Data *next; }; Data *head; void awal(){ head=NULL; } bool isEmpty(){ if (head==NULL) return true; return false; } void cetak(){ if (!isEmpty()){ Data *bantu; bantu=head; while(bantu!=NULL){ cout<<bantu->nama<<" "<<bantu->nilai<<endl; bantu=bantu->next; } } else { cout<<"List Kosong"; } } int main() { Data *baru; char lagi='y'; while (lagi=='y') { baru=(Data*) malloc(sizeof(Data)); cout<<"Nama : "; cin.getline(baru->nama,100); cout <<"Nilai : "; cin>>baru->nilai; if (isEmpty()) { baru->next=NULL; head=baru; } else { baru->next=head; head=baru; } cout<<"Masukan data lagi (y/n)? "; cin>>lagi; cin.ignore(1000, '\n'); } cetak(); return 0; }
Tuesday, September 25, 2012
Struktur Data: Single Linked List Non Circular Example
Monday, September 24, 2012
Algoritma & Struktur Data: Selection Sort
/* file: selection_sort.cpp @author Didik Kurniawan */ #include <iostream> using namespace std; int data[]={12,34,21,23,12,32,56,21,42,21,21,41,11,53,22}; int panjang=sizeof(data)/sizeof(data[0]); void swap(int &a, int &b) { int temp; temp=a; a=b; b=temp; } int max(int i){ int besar = data[0],idx_besar=0; for (int j=0;j<panjang-i;j++) { if (data[j]>besar) { besar=data[j]; idx_besar=j; } } return idx_besar; } int main(){ for (int i=0;i<panjang; i++){ cout<<data[i]<<", "; } cout<<endl<<"Sort with Selection" <<endl; for (int k=0;k<panjang; k++){ int besar=max(k); swap(data[besar],data[panjang-k-1]); } for (int i=0;i<panjang; i++){ cout<<data[i]<<", "; } return 0; }
Friday, September 21, 2012
J2ME: Contoh TextField dalam Form
/* * File name: FormMidlet.java */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * @author Daniel Siagian */ public class FormMidlet extends MIDlet implements CommandListener{ Display display; public Command keluar=new Command("Keluar",Command.EXIT,0); public Form form=new Form("Contoh form"); public TextField tf1=new TextField(null,null,32,TextField.ANY); public void startApp() { if (display==null) display=Display.getDisplay(this); form.append("Aplikasi mobile"); form.append("dibuat dengan java"); form.append("\noleh :"); form.append("\nDaniel Siagian"); form.append("-------------"); form.append("Nama :"); form.append(tf1); TextField tf2=new TextField(null,null,32,TextField.EMAILADDR); form.append("Email :"); form.append(tf2); TextField tf3=new TextField(null,null,32,TextField.NUMERIC); form.append("Umur :"); form.append(tf3); TextField tf4=new TextField(null,null,32,TextField.PHONENUMBER); form.append("Telpon :"); form.append(tf4); TextField tf5=new TextField(null,null,32,TextField.URL); form.append("Alamat Web :"); form.append(tf5); TextField tf6=new TextField(null,null,32,TextField.DECIMAL); form.append("DECIMAL :"); form.append(tf6); form.addCommand(keluar); form.setCommandListener(this); display.setCurrent(form); } public void commandAction(Command cmd, Displayable d){ System.out.print(cmd.toString()); if (cmd==keluar) { destroyApp(true); notifyDestroyed(); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }
Tuesday, September 18, 2012
Struktur Data: Insertion Sort Example
#include <iostream> using namespace std; struct product{ int product_id; string nama_product; string kategori; string satuan; float harga; string nama_perusahaan; }; int main() { product pd[100]; int jml_data,i; int cari; cin>>jml_data; for (i=0;i<jml_data;i++){ cin>>pd[i].product_id; cin.ignore(1000, '\n'); getline(cin,pd[i].nama_product,'\n'); getline(cin,pd[i].kategori,'\n'); getline(cin,pd[i].satuan,'\n'); cin>>pd[i].harga; cin.ignore(1000, '\n'); getline(cin,pd[i].nama_perusahaan,'\n'); } //proses sort dengan metode insertion sort product pd_sort[100]; pd_sort[0] = pd[0]; for (int j = 1;j<jml_data;j++) { i = j - 1; while ((0 <= i) and ( pd[j].product_id < pd_sort[i].product_id)) i = i - 1; for (int k = j;k>=i+2;k--) pd_sort[k] = pd_sort[k-1]; pd_sort[i+1] = pd[j]; } //akhir proses sort dengan metode insertion sort //cetak data for (i=0;i<jml_data;i++){ cout<<pd_sort[i].product_id<<"\t"; cout<<pd_sort[i].nama_product<<"\t"<<pd_sort[i].kategori<<"\t"<<pd_sort[i].satuan<<"\t"; cout<<pd_sort[i].harga<<"\t"<<pd_sort[i].nama_perusahaan<<endl; } return 0; }Technorati Profile
Struktur Data: Sequential Search
#include <iostream> using namespace std; struct product{ int product_id; string nama_product; string kategori; string satuan; float harga; string nama_perusahaan; }; int main() { product pd[100]; int jml_data,i; int cari; cin>>jml_data; for (i=0;i<jml_data;i++){ cin>>pd[i].product_id; cin.ignore(1000, '\n'); getline(cin,pd[i].nama_product,'\n'); getline(cin,pd[i].kategori,'\n'); getline(cin,pd[i].satuan,'\n'); cin>>pd[i].harga; cin.ignore(1000, '\n'); getline(cin,pd[i].nama_perusahaan,'\n'); } cout<<"Kode produk :"; cin>>cari; for (i=0;i<jml_data;i++){ if (pd[i].product_id==cari) { cout<<pd[i].product_id<<"\t"; cout<<pd[i].nama_product<<"\t"<<pd[i].kategori<<"\t"<<pd[i].satuan<<"\t"; cout<<pd[i].harga<<"\t"<<pd[i].nama_perusahaan<<endl; } } return 0; }
Friday, September 14, 2012
Pemrograman Mobile: Membuat Form J2ME
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ContohForm extends MIDlet { Display display; Form myForm; TextField tfEmail; TextField tfNama; DateField strTtl; public void inisialisasi() { myForm=new Form("Form pertama"); tfEmail=new TextField("Email :","",10,TextField.EMAILADDR); tfNama=new TextField("Nama :","",10,TextField.ANY); strTtl=new DateField("TTL :",DateField.DATE); myForm.append(tfNama); myForm.append(tfEmail); myForm.append(strTtl); } public void startApp() { inisialisasi(); if (display==null){ display=Display.getDisplay(this); display.setCurrent(myForm); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }Type your summary here Type rest of the post here Technorati Profile
Thursday, September 13, 2012
Struktur Data: Contoh membuat ADT dengan C++
#include <iostream>
using namespace std;
struct product{
string nama_product;
string kategori;
string satuan;
float harga;
string nama_perusahaan;
};
int main() {
product pd[100];
int jml_data,i;
cout<<"Banyak Data : ";
cin>>jml_data;
cin.ignore(1000, '\n');
for (i=0;i<jml_data;i++){
cout<<"Product ke "<<(i+1)<<endl;
cout<<"Nama Product : ";
getline(cin,pd[i].nama_product,'\n');
cout<<"Kategori product : ";
getline(cin,pd[i].kategori,'\n');
cout<<"Satuan : ";
getline(cin,pd[i].satuan,'\n');
cout<<"Harga : ";
cin>>pd[i].harga;
cin.ignore(1000, '\n');
cout<<"Nama perusahaan : ";
getline(cin,pd[i].nama_perusahaan,'\n');
}
for (i=0;i<jml_data;i++){
cout<<pd[i].nama_product<<"\t"<<pd[i].kategori<<"\t"<<pd[i].satuan<<"\t";
cout<<pd[i].harga<<"\t"<<pd[i].nama_perusahaan<<endl;
}
return 0;
}
Type your summary here Type rest of the post here Technorati Profile
using namespace std;
struct product{
string nama_product;
string kategori;
string satuan;
float harga;
string nama_perusahaan;
};
int main() {
product pd[100];
int jml_data,i;
cout<<"Banyak Data : ";
cin>>jml_data;
cin.ignore(1000, '\n');
for (i=0;i<jml_data;i++){
cout<<"Product ke "<<(i+1)<<endl;
cout<<"Nama Product : ";
getline(cin,pd[i].nama_product,'\n');
cout<<"Kategori product : ";
getline(cin,pd[i].kategori,'\n');
cout<<"Satuan : ";
getline(cin,pd[i].satuan,'\n');
cout<<"Harga : ";
cin>>pd[i].harga;
cin.ignore(1000, '\n');
cout<<"Nama perusahaan : ";
getline(cin,pd[i].nama_perusahaan,'\n');
}
for (i=0;i<jml_data;i++){
cout<<pd[i].nama_product<<"\t"<<pd[i].kategori<<"\t"<<pd[i].satuan<<"\t";
cout<<pd[i].harga<<"\t"<<pd[i].nama_perusahaan<<endl;
}
return 0;
}
Type your summary here Type rest of the post here Technorati Profile
Subscribe to:
Posts (Atom)