You are on page 1of 4

TUGAS SLL DATA INT

INSERT AFTER

NAMA : ZALATISYAM KHOIRI


NRP : 2103187054

JURUSAN TEKNIK INFORMATIKA


POLITEKNIK ELEKTRONIKA NEGERI SURABAYA
TAHUN 2019
LISTING
#include <stdio.h>
#include <stdlib.h>

typedef struct simpul node;

struct simpul {
int data;
node *next;
};

void alokasi ();


void insertawal ();
void tampil ();
void insertafter();

node *p, *head, *after;


int key;

int main()
{
char jawab;

printf("SLL data int - INSERT AFTER\n\n ");


do{
alokasi();
fflush(stdin);
insertawal();
fflush(stdin);
tampil();
fflush(stdin);

printf("\nINGIN MENYISIPKAN DATA LAGI ?");


fflush(stdin);
scanf("%c",&jawab);
}while(jawab=='y' || jawab=='Y');

if(jawab='t' || jawab=='T')
{
printf("\nMASUKKAN KEY : ");
scanf("%d",&key);
alokasi();
fflush(stdin);
insertafter();
fflush(stdin);
tampil();
}

return 0;
}
void alokasi()
{
int x;

printf("\nMASUKKAN KARAKTER DATA : ");


fflush(stdin);
scanf("%d",&x);

p=(node *)malloc(sizeof(node));
p->data=x;
p->next=NULL;
}
void insertawal()
{
if(head==NULL)
head=p;
else
{
p->next=head;
head=p;
}
}
void tampil()
{
node *baca;

printf("ISI DARI SINGLE LINKED LIST\n");

baca=head;

while(baca!=NULL)
{
printf("%d\n",baca->data);
fflush(stdin);
baca=baca->next;

}
}
void insertafter()
{
after=head;
while(after->data!=key){
if(after->next==NULL){
puts("KEY TIDAK ADA");
exit(0);
}
else
after=after->next;
p->next=after->next;
after->next=p;
}

SCREENSHOT

You might also like