#include "stdio.h"
void main()
{
int stack[100];
int top=-1;
int pilih, i;
do
{
printf("MENU\n");
printf("1. PUSH\n2. POP\n3. VIEW\n4. EXIT\n");
printf("Pilih = "); scanf("%d", &pilih);
switch(pilih)
{
case 1://push
if (top > 100)
printf("Stack penuh!\n");
else
{ printf("Data = "); scanf("%d", &stack[top+1]);
top++;
}
break;
case 2://pop
if (top < 0)
printf("Stack kosong!\n");
else
{
printf("Data keluar = %d\n", stack[top]);
top--;
}
break;
case 3://view
for(i=top; i>=0; i--)
printf("%d ", stack[i]);
printf("\n");
break;
case 4:
printf("Exit...\n");
break;
}
}while (pilih!=4);
}
Artikel terkait:
Stack Array Java
Stack Linked List Java
Why is Called Java Language?
Pertama kali mendengar namanya membuat saya penasaran: Java Programming Language. Muncul banyak spekulasi:
1. Developernya orang Jawa?
2. Developernya pernah ke dan terkesan dengan Jawa?
3. Developernya keturunan orang Jawa?
4. Anything else? Sangat membingungkan...
Akhirnya saya telusuri dengan Google. Saya dapatkan dua buah artikel yang kutipannya berikut ini:
"I believe the name was first suggested by Chris Warth," said Arthur van Hoff, a senior engineer on the project and now CTO of Marimba Inc. "We had been in the meeting for hours and, while he was drinking a cup of Peet's Java, he picked 'Java' as an example of yet another name that would never work. The initial reaction was mixed. I believe the final candidates were Silk, DNA, and Java, however. I suggested Lingua Java, but that didn't make it.... We could not trademark the other names, so Java ended up being the name of choice. In the end, our marketing person, Kim Polese, finally decided to go ahead with it."
Source: http://www.javaworld.com/javaworld/jw-10-1996/jw-10-javaname.html?page=2
Arabian Mocha-Java
The world's most famous coffee blend; full-bodied, bittersweet chocolate overtones enhance Mocha-Java's rich, complex flavors. Mocha-Java is the world's most famous coffee blend. When someone first thought of combining these two origins, it was before coffee was widely grown around the world. These two coffees were undoubtedly much different from those which the countries of Yemen and Indonesia (note: maybe from Java island) produce today, although Yemen still produces its coffee under very primitive conditions.
As with any blend everything depends on the quality of the coffees used, and in this case the result is a delicious full-bodied coffee with bittersweet chocolate overtones on top of rich and complex flavors. While Americans associate the word mocha with chocolate, they've reversed the facts: when cocoa was first refined and sold in Europe, it reminded people of Mocha coffee from Yemen.
Source: http://www.peets.com/shop/coffee_detail.asp?rdir=1&id=49
1. Developernya orang Jawa?
2. Developernya pernah ke dan terkesan dengan Jawa?
3. Developernya keturunan orang Jawa?
4. Anything else? Sangat membingungkan...
Akhirnya saya telusuri dengan Google. Saya dapatkan dua buah artikel yang kutipannya berikut ini:
"I believe the name was first suggested by Chris Warth," said Arthur van Hoff, a senior engineer on the project and now CTO of Marimba Inc. "We had been in the meeting for hours and, while he was drinking a cup of Peet's Java, he picked 'Java' as an example of yet another name that would never work. The initial reaction was mixed. I believe the final candidates were Silk, DNA, and Java, however. I suggested Lingua Java, but that didn't make it.... We could not trademark the other names, so Java ended up being the name of choice. In the end, our marketing person, Kim Polese, finally decided to go ahead with it."
Source: http://www.javaworld.com/javaworld/jw-10-1996/jw-10-javaname.html?page=2
Arabian Mocha-Java
The world's most famous coffee blend; full-bodied, bittersweet chocolate overtones enhance Mocha-Java's rich, complex flavors. Mocha-Java is the world's most famous coffee blend. When someone first thought of combining these two origins, it was before coffee was widely grown around the world. These two coffees were undoubtedly much different from those which the countries of Yemen and Indonesia (note: maybe from Java island) produce today, although Yemen still produces its coffee under very primitive conditions.
As with any blend everything depends on the quality of the coffees used, and in this case the result is a delicious full-bodied coffee with bittersweet chocolate overtones on top of rich and complex flavors. While Americans associate the word mocha with chocolate, they've reversed the facts: when cocoa was first refined and sold in Europe, it reminded people of Mocha coffee from Yemen.
Source: http://www.peets.com/shop/coffee_detail.asp?rdir=1&id=49
Contoh Program C++: STL List dan String
#include "iostream.h"
#include "list" // list class library
#include "string" // string class library
using namespace std;
void main()
{
list words;
list::iterator words_iter;
words.push_front("Hello");
words.push_front("World");
unsigned int total_length = 0;
for (words_iter=words.begin(); words_iter != words.end(); words_iter++)
{
cout<data()<<" ";
total_length += (*words_iter).length(); // correct
}
cout<<endl;
cout << "Total length is " << total_length << endl;
}
Download Source Code
#include "list" // list class library
#include "string" // string class library
using namespace std;
void main()
{
list words;
list::iterator words_iter;
words.push_front("Hello");
words.push_front("World");
unsigned int total_length = 0;
for (words_iter=words.begin(); words_iter != words.end(); words_iter++)
{
cout<data()<<" ";
total_length += (*words_iter).length(); // correct
}
cout<<endl;
cout << "Total length is " << total_length << endl;
}
Download Source Code
Contoh Program C++: Standard Template Library
STL singkatan dari Standard Template Library. Compiler C++ telah menyediakan library khusus untuk menampung beberapa template yang memang secara umum sering dipakai dalam pembuatan program. Dengan adanya STL, programmer tidak perlu lagi coding dari nol dan mulai awal. Namun cukup memanfaatkan template yang sudah dijadikan library tersebut. Tugas programmer tinggal menganalisa dan memilih template mana yang paling cocok dengan kebutuhan programnya. Di dalam template sudah disediakan container class lengkap dengan fungsi-fungsinya. Berikut adalah salah satu contoh penggunanan STL list untuk mengimplementasikan linked list:
#include "iostream.h"
#include "list" //standard template library
using namespace std;
int main(){
list values, otherValues;
values.push_front(1);
values.push_front(2);
values.push_back(4);
values.push_back(3);
list::iterator p; //pointer u/ mengakses isi container class
for (p=values.begin(); p!=values.end(); p++)
{
cout << *p <<endl;
}
return 0;
}
#include "iostream.h"
#include "list" //standard template library
using namespace std;
int main(){
list values, otherValues;
values.push_front(1);
values.push_front(2);
values.push_back(4);
values.push_back(3);
list::iterator p; //pointer u/ mengakses isi container class
for (p=values.begin(); p!=values.end(); p++)
{
cout << *p <<endl;
}
return 0;
}
Contoh Program C++: Template
Dilihat dari aspek manfaatnya, pembuatan template hampir sama dengan function overloading. Cukup dipanggil satu yang sama, namun bisa menangani tipe data yang berbeda-beda. Namun, bedanya adalah jika kita memakai overloading maka untuk setiap fungsi harus kita tuliskan kembali definisinya.
Tidak demikian dengan template yang cukup ditulis satu kali saja (kerangkanya) maka compiler akan otomatis bisa membedakan jenis-jenis tipe datanya. Memang akan menjadi jauh lebih sederhana. Tetapi harus benar-benar dianalisa secara mendalam apakah konsep template sudah pas dengan yang dibutuhkan dalam rangka memecahkan sebuah studi kasus. Berikut adalah beberapa contohnya:
Template Fungsi
Template Class 1
Template Class 2
Note: Ubahlah terlebih dulu ekstensi doc menjadi cpp.
Tidak demikian dengan template yang cukup ditulis satu kali saja (kerangkanya) maka compiler akan otomatis bisa membedakan jenis-jenis tipe datanya. Memang akan menjadi jauh lebih sederhana. Tetapi harus benar-benar dianalisa secara mendalam apakah konsep template sudah pas dengan yang dibutuhkan dalam rangka memecahkan sebuah studi kasus. Berikut adalah beberapa contohnya:
Template Fungsi
Template Class 1
Template Class 2
Note: Ubahlah terlebih dulu ekstensi doc menjadi cpp.
Subscribe to:
Posts (Atom)