Professional Documents
Culture Documents
Tugas Linked List (Putra Ramadandi - 121130048 - PMC RD)
Tugas Linked List (Putra Ramadandi - 121130048 - PMC RD)
NIM : 121130048
Kelas : RD
Jawaban:
#include <stdlib.h>
struct Node
char huruf;
void cetak();
int main()
tambah('P');
tambah('u');
tambah('t');
tambah('r');
tambah('a');
tambah(' ');
tambah('R');
tambah('a');
tambah('m');
tambah('a');
tambah('d');
tambah('a');
tambah('n');
tambah('d');
tambah('i');
printf("\nNama lengkap : ");
cetak();
return 0;
newNode->huruf = huruf;
newNode->next = NULL;
if (head == NULL)
head = newNode;
tail = newNode;
else
tail->next = newNode;
tail = newNode;
int countNode()
int count = 0;
temp = head;
temp = temp->next;
count++;
return count;
void cetak()
{
temp = head;
printf("%c", temp->huruf);
temp = temp->next;
2. NIM (121130048)
#include <stdio.h>
#include <stdlib.h>
struct Node
{
char angka;
struct Node *next;
} * head, *tail, *newNode, *temp, *temp2, *del;
void tambah(char angka);
void cetak();
int main()
{
head = tail = NULL;
tambah('1');
tambah('2');
tambah('1');
tambah('1');
tambah('3');
tambah('0');
tambah('0');
tambah('4');
tambah('8');
printf("\nNIM : ");
cetak();
return 0;
}
void tambah(char angka)
{
newNode = (struct Node *)malloc(sizeof(struct Node));
newNode->angka = angka;
newNode->next = NULL;
if (head == NULL)
{
head = newNode;
tail = newNode;
}
else
{
tail->next = newNode;
tail = newNode;
}
}
int countNode()
{
int count = 0;
temp = head;
while (temp != NULL)
{
temp = temp->next;
count++;
}
return count;
}
void cetak()
{
temp = head;
while (temp != NULL)
{
printf("%c", temp->angka);
temp = temp->next;
}
}
3. Delete node yang ke-3 dari nama (Putra Ramadandi= yang ke-3 yaitu huruf “t”)
#include <stdio.h>
#include <stdlib.h>
struct Node
char huruf;
struct Node *next;
void cetak();
int main()
tambah('P');
tambah('u');
tambah('t');
tambah('r');
tambah('a');
tambah(' ');
tambah('R');
tambah('a');
tambah('m');
tambah('a');
tambah('d');
tambah('a');
tambah('n');
tambah('d');
tambah('i');
cetak();
hapus(3);
cetak();
return 0;
{
newNode = (struct Node *)malloc(sizeof(struct Node));
newNode->huruf = huruf;
newNode->next = NULL;
if (head == NULL)
head = newNode;
tail = newNode;
else
tail->next = newNode;
tail = newNode;
int countNode()
int count = 0;
temp = head;
temp = temp->next;
count++;
return count;
int count = 1;
temp = head;
temp2 = head;
{
if (count == urutan)
del = temp;
if (count == urutan - 1)
temp2 = temp;
temp = temp->next;
count++;
temp2->next = temp;
free(del);
void cetak()
temp = head;
printf("%c", temp->huruf);
temp = temp->next;
}
4. Delete node yang ke-4 dari NIM (121130048 = yang ke-4 yaitu angka “1”)
#include <stdio.h>
#include <stdlib.h>
struct Node
char angka;
void cetak();
int main()
tambah('1');
tambah('2');
tambah('1');
tambah('1');
tambah('3');
tambah('0');
tambah('0');
tambah('2');
tambah('8');
printf("\nNIM : ");
cetak();
hapus(4);
printf("\nNIM : ");
cetak();
return 0;
}
newNode->angka = angka;
newNode->next = NULL;
if (head == NULL)
head = newNode;
tail = newNode;
else
tail->next = newNode;
tail = newNode;
int countNode()
int count = 0;
temp = head;
temp = temp->next;
count++;
return count;
int count = 1;
temp = head;
temp2 = head;
if (count == urutan)
del = temp;
if (count == urutan - 1)
temp2 = temp;
temp = temp->next;
count++;
temp2->next = temp;
free(del);
void cetak()
temp = head;
printf("%c", temp->angka);
temp = temp->next;