Linked List
In this blog I want to explain to you what Linked List is. There are 3 types of Linked List that commonly used by people. The first one and the simplest one is Singly Linked List, and then there's also Circular Singly Linked List and Doubly Linked List. But in this blog I'll only cover Singly and Doubly Linked List only.
1. Singly Linked List
Singly Linked List is the simplest method of Linked List because of the simplicity the code have, the first thing you need to do to make a Linked List of course making a struct and make sure declare head and tail. What is head and tail? Head means the first data from the front and Tail means the last data that you can input.
Example :
#include<stdio.h>
struct Mahasiswa{
int nim;
char nama[100];
double ipk;
Mahasiswa *next;
}*head = 0, *tail = 0;
After you declare the struct make sure you use malloc to allocate the memory to the struct for the dynamic memory, which mean you don't need to declare the size of the memory you need to use like in array. In Singly Linked List there's two method you can use there's Insert and Deletion.
Insert means you can dynamically insert data to the struct. You can Insert from the front(head), back(tail), and middle(mid), and most of the times programmers usually use pushHead for inserting from the front, pushTail for inserting from the back of the linked list, and pushMid for inserting from the middle of the linked list.
And delete means you can choose from where the data you inputed which data you want to delete. Most of the programmer like to use popHead, popTail, and popMid for the variables, popHead means you delete the front of the data, popTail means you delete the end of the data, and popMid is deleting the middle of the data. In Singly Linked List you
2. Doubly Linked List
Doubly Linked List is just as the same as Singly Linked List, the difference between Doubly and Singly is Doubly have two nodes which is next and prev, and Singly have only one node that is next. Doubly Linked List is more effective than Singly Linked List because of Doubly Linked List have more complexity than Singly Linked List.
Doubly Linked List also have Insert and Deletion method. And pretty much all of the function is the same. What different about Doubly Linked List method of inserting is more complicated than Singly Linked List, because of you need to point the value to next and then prev and then head/tail and then it append it self to the code.
And the deletion for Doubly Linked List have four major problems, the first one if you only want to delete the only node there is, which you can do by changing the value of head and tail to NULL. The second one is if you want to delete the head, in which you can do by pointing head to next and then free the memory inside head that pointing to prev and then change the value to NULL. The third one is if you want to delete the tail, which you can do by pointing tail to prev and then free the memoty inside that tail that pointing to next and then change the value to NULL. And the last one is deleting any node that's not the head/tail.
Source :
https://www.geeksforgeeks.org/data-structures/linked-list/
PowerPoint Linked List I (Session 2), Linked List II (Session 4).
In this blog I want to explain to you what Linked List is. There are 3 types of Linked List that commonly used by people. The first one and the simplest one is Singly Linked List, and then there's also Circular Singly Linked List and Doubly Linked List. But in this blog I'll only cover Singly and Doubly Linked List only.
1. Singly Linked List
Singly Linked List is the simplest method of Linked List because of the simplicity the code have, the first thing you need to do to make a Linked List of course making a struct and make sure declare head and tail. What is head and tail? Head means the first data from the front and Tail means the last data that you can input.
Example :
#include<stdio.h>
struct Mahasiswa{
int nim;
char nama[100];
double ipk;
Mahasiswa *next;
}*head = 0, *tail = 0;
After you declare the struct make sure you use malloc to allocate the memory to the struct for the dynamic memory, which mean you don't need to declare the size of the memory you need to use like in array. In Singly Linked List there's two method you can use there's Insert and Deletion.
Insert means you can dynamically insert data to the struct. You can Insert from the front(head), back(tail), and middle(mid), and most of the times programmers usually use pushHead for inserting from the front, pushTail for inserting from the back of the linked list, and pushMid for inserting from the middle of the linked list.
And delete means you can choose from where the data you inputed which data you want to delete. Most of the programmer like to use popHead, popTail, and popMid for the variables, popHead means you delete the front of the data, popTail means you delete the end of the data, and popMid is deleting the middle of the data. In Singly Linked List you
2. Doubly Linked List
Doubly Linked List is just as the same as Singly Linked List, the difference between Doubly and Singly is Doubly have two nodes which is next and prev, and Singly have only one node that is next. Doubly Linked List is more effective than Singly Linked List because of Doubly Linked List have more complexity than Singly Linked List.
Doubly Linked List also have Insert and Deletion method. And pretty much all of the function is the same. What different about Doubly Linked List method of inserting is more complicated than Singly Linked List, because of you need to point the value to next and then prev and then head/tail and then it append it self to the code.
And the deletion for Doubly Linked List have four major problems, the first one if you only want to delete the only node there is, which you can do by changing the value of head and tail to NULL. The second one is if you want to delete the head, in which you can do by pointing head to next and then free the memory inside head that pointing to prev and then change the value to NULL. The third one is if you want to delete the tail, which you can do by pointing tail to prev and then free the memoty inside that tail that pointing to next and then change the value to NULL. And the last one is deleting any node that's not the head/tail.
Source :
https://www.geeksforgeeks.org/data-structures/linked-list/
PowerPoint Linked List I (Session 2), Linked List II (Session 4).
Comments
Post a Comment