Documente Academic
Documente Profesional
Documente Cultură
#4.
12 APRIL 2013
Kompetensi 5
Kompetensi 5
Kompetensi 5
Lat 5_Listke1
5.
int main()
7. {
8.
list<int> coll;
// list container for integer elements
9.
list<int>::iterator pos; //Menggunakan iterator sebagai penunjuk pointer element List<int>
6.
10.
11.
12.
13.
14.
15.
16.
17.
18.
system("PAUSE");
return 0;
19.
20.
21.
Kompetensi 5 : Iterasi
Pointer pos
Kompetensi
5
// Latihan Kompetensi 5:: LIST
Lat 5_Listke2
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
// File : Lat5_Listke2.cpp
#include <cstdlib>
#include <iostream>
#include <list>
using namespace std;
int main() {
list<int> coll;
// list container for integer elements
list<int>::iterator pos; //Menggunakan iterator sebagai penunjuk pointer element List<int>
// append elements from 1 to 20
for (int c=1; c<=20; ++c) {
coll.push_front(c);
}
// Print info pada seluruh node dari struktur List coll
for (pos=coll.begin(); pos!=coll.end(); ++pos)
{
cout << (*pos) << ' ';
cout << endl ;
}
system("PAUSE");
return 0;
}
Searching By Boolean
// Searching by Boolean : mengembalikan nilai boolean true atau false
// Cari nilai angka 17.
pos=coll.begin();
bool found;
found=false;
while ((!found)&&(pos != coll.end())){
if ((*pos)== 17){
found = true;
}
else {
pos++;
}
}
if (found){
cout << "Angka : " << (*pos) << " Ditemukan " << ' ';
}
else { // Yang dicari tidak ketemu
cout << "Angka : " << (*pos) << "Tidak Ditemukan " << ' ';
POTONGAN PROGRAM
UTAMA
LATIHAN 5.1
Gabungkan source code dalam Lat5_Listke2.cpp
Return of Function
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
Function Name
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
Parameter
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
CALL OF FUNCTION
Panah kiri sebagai alur pemanggilan
fungsi SearchingByBoolean, dengan
membawa parameter coll dan 21
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
coll, 21
found
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
';
15.
16.
Panah kanan sebagai alur pengembalian
nilai fungsi ke pemanggil di program
utama, fungsi mengembalikan nilai yang
tersimpan dalam variabel found bertipe
boolean
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
21
coll, 21
found
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
';
15.
16.
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
21
coll, 21
found
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
';
15.
16.
}
}
Return of Function
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
CALL OF FUNCTION
2. RETURN VALUE
3. PROSES PENYALINAN PARAMETER
1.
1.
19
{
3. // Deklarasi variabel
4.
list<int>::iterator ps;
5.
bool found;
6.
ps=cll.begin();
7.
found=false;
8. // Algoritma
9. ..........................
10. return ps;
11. }
2.
coll, 19
ps
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
Latihan 5.2
1.
Tugas Kelompok
Menyusun Program Yang memuat Fungsi