• Tidak ada hasil yang ditemukan

Think Different Materi ASD (SISKOM)

N/A
N/A
Protected

Academic year: 2017

Membagikan "Think Different Materi ASD (SISKOM)"

Copied!
21
0
0

Teks penuh

(1)

Algoritma dan Struktur Data

(2)

Definition —

Structure

• Beberapa variabel (dapat berbeda tipe)

(3)

Syntax:

struct nama_struct {

tipe_data_1 nama_var_1; tipe_data_2 nama_var_2; tipe_data_3 nama_var_3; ……

};

(4)

struct

• Penting untuk implementasi ADT /

membuat tipe data baru

• E.g.,

struct motor {

float volts; //voltage of the motor

float amps; //amperage of the motor

int phases; //# of phases of the motor

float rpm; //rotational speed of motor

};

(5)

struct

• E.g.,

struct motor { float volts; float amps; int phases; float rpm; };

typedef struct motor motor;

Name of

(6)

struct

• E.g.,

struct motor { float volts; float amps; int phases; float rpm; };

typedef struct motor motor;

Members of the

(7)

struct

• Mendefinisikan tipe data baru

• E.g.,

struct motor {

float volts;

float amps;

int phases;

float rpm;

};

typedef struct motor motor;

Agar pa

da saat d

eklarasi

variabel

cukup d

engan

memangg

il motor

(8)

Menggunakan tipe data baru

motor p, q, r;

• Mendefinisikan tiga variable – p, q, dan r – masing masing bertipe data motor

motor M[25];

• Mendeklarasikan array M berisi 25 data bertipe motor

motor *m;

(9)

Mengakses anggota

struct

• Deklarasi

motor p;

motor q[10];

• Maka

p.volts — is the voltage

p.amps — is the amperage

p.phases — is the number of phases

p.rpm — is the rotational speed

q[i].volts — is the voltage of the ith motor

q[i].rpm — is the speed of the ith motor

(10)
(11)

• Sebuah kondisi dimana di dalam sebuah struct terdapat tipe data berupa struct lagi.

(12)

• Contoh (Ubah ke C++)

(13)

• Sebuah array yang setiap data elemennya bertipe struct.

Umumnya dipakai untuk menyimpan object data yang terstruktur, misal: data mahasiswa, karyawan, buku, barang, dsb.

(14)
(15)

Mengakses elemen

struct

menggunakan pointer

• Deklarasi

motor *p;

• Maka

(*p).volts — is the voltage of the motor pointed

to by p

(*p).phases — is the number of phases of the motor pointed to by p

Mengapa

memakai

(16)

Mengakses elemen

struct

menggunakan pointer

• Notasi

(*p).member

kurang nyaman

dipakai

• Cara yang lebih singkat

p->member

, di mana p merupakan variabel

(17)

Contoh sebelumnya menjadi …

• Deklarasi

motor *p;

• Maka

p -> volts — is the voltage of the motor pointed

to by p

(18)

contoh

struct motor { float volts; float amps; };

typedef struct motor motor; int main()

{

motor m1; motor *pm1;

m1.volts = 100; m1.amps = 110;

pm1 = &m1;

cout << “voltase motor m1 : “ << m1.volts; cout << “\namps motor m1 : “ << m1.amps; cout << “\nvoltase motor m1 : “ << pm1->volts; cout << “\namps motor m1 :“ << pm1->amps; getch();

(19)
(20)

Operasi pada

struct

• Copy/assign

struct motor p, q; p = q;

• Get address

struct motor p; struct motor *s s = &p;

• Access members

(21)

Example

struct item {

char *s;

struct item *next;

}

• Sebuah item dapat berisi alamat item lain…

yang dapat menunjuk item lain

yang juga dapat menunjuk item yang lain lagi

etc.

Dengan demikian membentuk rangkaian

item!!!

Yes! Thi

Referensi

Dokumen terkait

Model U2 (Diketik) dilampiri fotokopi bukti pembayaran ujian dari Bank4. Fotokopi Sertifikat

The ash content was lowest in the stem fraction for all species and at both harvest times, in leaf sheaths and especially in leaf blades the ash content was clearly higher (Table

Utilising as raw material only the fibrous frac- tion of miscanthus plants, the objectives of the present study were: (a) to investigate the feasibil- ity of obtaining papermaking

Fine chopping of stalk materials significantly influence compacting density and is more prefer- able to heating, because energy requirement for chopping − 25 kJ / kg is one order

The lactide ring opening polymerisation reaction reaches the state of equilibrium within the resi- dence time of the reactive material inside the extrusion system and can thus be

Dinyatakan LULUS / TIDAK LULUS dengan perbaikan skripsi seperti tercantum dalam tabel berikut dan dengan jangka waktu perbaikan 1 (satu)

Yang bertanda tangan di bawah ini menyatakan dengan sebenarnya, bahwa mahasiswa : Nama : NIM : Jurusan : ..4. Telah bebas dari tanggungan pinjaman selama tahun akademik

This, together with the fact that the acidified plant juice is an excellent medium for par example amino acid producing strains of Corynebacterium glutamicum , leads us to