DOSEN :
OLEH :
D3 LJ PJJ AK TI-A
2021
1. INSERT AWAL
#include <stdio.h>
#include <stdlib.h>
int main()
{
char jwb;
do{
fflush(stdin);
alokasi();
awal();
fflush(stdin);
printf("Lagi (y/t) ?");
jwb = getchar();
}while(jwb=='y'||jwb=='Y');
puts("");
tampil();
return 0;
}
void tampil(){
Node *baca;
Hasil Output :
2. INSERT AKHIR
#include <stdio.h>
#include <stdlib.h>
int main()
{
char jwb;
puts("Single Linked List - Insert di Akhir : ");
do{
fflush(stdin);
alokasi();
akhir();
fflush(stdin);
printf("Lagi (y/t) ?");
jwb = getchar();
}while(jwb=='y'||jwb=='Y');
puts("");
tampil();
return 0;
}
void akhir(){
Node *tail;
if(head==NULL)
head = p;
else{
tail = head;
while(tail->next != NULL)
tail = tail->next;
tail->next = p;
tail = tail->next;
}
void tampil(){
Node *baca;
Hasil Output :
3. INSERT AFTER
#include <stdio.h>
#include <stdlib.h>
int main()
{
char jwb;
puts("Single Linked List - Insert di AFTER : ");
do{
fflush(stdin);
alokasi();
akhir();
fflush(stdin);
printf("Lagi (y/t) ?");
jwb = getchar();
}while(jwb=='y'||jwb=='Y');
puts("");
tampil();
fflush(stdin);
puts("Insert after node tertentu");
alokasi();
fflush(stdin);
setelah();
tampil();
return 0;
}
void setelah (){
Node *after;
int key;
printf("Disisipkan setelah data berapa ? ");
scanf("%d", &key);
after = head;
while (after->data != key){
if (after->next == NULL){
p->next =after->next;
after->next = p;
void akhir(){
Node *tail;
if(head==NULL)
head = p;
else{
tail = head;
while(tail->next != NULL)
tail = tail->next;
tail->next = p;
tail = tail->next;
}
void tampil(){
Node *baca;
Hasil Output :
4. INSERT BEFORE
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char jwb; puts("Single Linked List - Insert di Akhir");
do {
fflush (stdin);
alokasi();
akhir();
fflush(stdin);
printf ("Lagi (y/t)?");
jwb = getchar ();
} while ((jwb=='y')||(jwb=='Y'));
puts("");
tampil (); fflush(stdin); puts("Insert Before node tertentu");
alokasi();
fflush (stdin);
sebelum ();
tampil ();
return 0;
}
void akhir (){
Node *tail;
if (head==NULL)
head = p;
else {
tail=head;
while (tail->next!=NULL)
tail=tail->next;
tail->next=p;
tail=tail->next;
}
}
void tampil (){
Node *baca;
puts("isi dari SLL");
baca = head;
while(baca !=NULL){
printf("%d\n",baca ->data);
baca = baca -> next;
}
}
Hasil Output :
Kesimpulan :
Pada praktikum SSL Insert adanya perbedaan secara signifikan pada masing-masing Fungsi
Insert Awal, Akhir, After dan Before.
Dimulai dari codding yang berbeda serta harus dibutuhkan ketelitian dalam hal menulis script
codding, sebab disini saya mendapat banyak problem mulai dari codding yang menurut saya
sudah sama dengan yang di video akan tetapi ada beberapa karakter yang harus di teliti lagi
supaya hasil output sesuai dengan yang di perintahkan pada praktikum kali ini.