Upcoming SlideShare
×

# Modul 2

1,313
-1

Published on

Published in: Technology, Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
1,313
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
28
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Modul 2

1. 1. LAPORAN PRAKTIKUM STRUKTUR DATA MODUL 2 Probo Tri Laksono 123090143 / Plug 9 Assdos / Coass Widy Sulistianto / Dian Andarini JURUSAN TEKNIK INFORMATIKA FAKULTAS TEKNOLOGI INDUSTRI UPN 'VETERAN' YOGYAKARTA 2010
2. 2. TUGAS 1. Program 3.2 #include<stdio.h> #include<malloc.h> typedef int typeinfo; typedef struct typenode *typeptr; typedef struct typenode { typeinfo info; typeptr next; }xx; typeptr awal, akhir; void buatlistbaru(); void sisipdepan(typeinfo IB); void sisipbelakang(typeinfo IH); void sisiptengah(typeinfo IH); void hapuslist(typeinfo IH); void cetaklist(); int main() { buatlistbaru(); sisipdepan(10); sisipbelakang(25); sisipbelakang(100); sisiptengah(50); cetaklist(); hapuslist(50); //clrscr(); printf("nn"); cetaklist(); return 0; } void buatlistbaru() { typeptr list; list=(typenode *)malloc(sizeof(typenode)); list=NULL; awal=list; akhir=list; } void sisipdepan(typeinfo IB) { typeptr NB; NB=(typenode *)malloc(sizeof(typenode)); NB->info=IB; if(awal==NULL) { awal=NB; akhir=NB; } else { NB->next=awal; } awal=NB; } void sisipbelakang(typeinfo IB) { typeptr NB; NB=(typenode *)malloc(sizeof(typenode));
3. 3. NB->info=IB; if(awal==NULL) { awal=NB; akhir=NB; } else { akhir->next=NB; } akhir=NB; akhir->next=NULL; } void sisiptengah(typeinfo IB) { typeptr NB, bantu; NB=(typenode *)malloc(sizeof(typenode)); NB->info=IB; NB->next=NULL; if(awal==NULL) { awal=NB; akhir = NB; } else { bantu=awal; while((IB > bantu->next->info) && (bantu->next!=NULL)) bantu=bantu->next; NB->next=bantu->next; bantu->next=NB; } } void hapuslist(typeinfo IH) { typeptr hapus, bantu; if(awal==NULL) { printf("List masih kosong! n"); } else { if(awal->info==IH) { hapus=awal; awal=hapus->next; free(hapus); } else { bantu=awal; while((bantu->next->info!=IH)&&(bantu->next!=NULL)) { bantu=bantu->next; } hapus=bantu->next; if(hapus==NULL) { printf("List tidak ditemukann"); } else { bantu->next=hapus->next; } free(hapus); } } } void cetaklist() { typeptr bantu; bantu=awal; while(bantu!=NULL) { printf("%d ",bantu->info); bantu=bantu->next; }}