Selasa, 25 Februari 2020

Data Structure summary




What I’ve learned today:
-a circular single linked list is a variation of linked list in which the first element points to the last element and the last element points to the first element. Both singly linked list and doubly linked list can be made into a circular linked list
-In the circular linked list, the last node contains a pointer to the first node and there is no storing of NULL values in the list.
Example:



-Doubly linked list is a linked list data structure with to link, one that contain reference to the next data and one that contain reference to the previous data.
-circular Doubly linked list is similar with circular single linked list, but total pointer in each node here is two pointers
-if we want to insert doubly linked list the first thing that we need to do is we should allocate new node and assign the value to it, and then we connect the node with the existing linked list. This is the example for insertion operation:
insertFirst(data):
Begin
   create a new node
   node -> data := data
   if the list is empty, then
      head := node
      next of node = head
   else
      temp := head
      while next of temp is not head, do
      temp := next of temp
      done
      next of node := head
      next of temp := node
      head := node
   end if
End


-there are 4 important things when we wanted to delete doubly linked list, first the node to be deleted  is the only node in linked list, second the node to be deleted are head, tail or not both of them. This is the example for deleting operation
deleteFirst():
Begin
   if head is null, then
      it is Underflow and return
   else if next of head = head, then
      head := null
      deallocate head
   else
      ptr := head
      while next of ptr is not head, do
         ptr := next of ptr
      next of ptr = next of head
      deallocate head
      head := next of ptr
   end if
End


Referensi: