This document summarizes different types of linked lists and their key characteristics. It describes:
1) Regular, circular, and doubly linked lists with their traversal directions.
2) The Node class which stores a node's data and next/prev pointers.
3) The Linkedlist class which contains a root node, size, and methods to add, find, remove and print nodes.
4) Circular linked lists which connect the last node to the first, allowing continuous looping.
This document summarizes different types of linked lists and their key characteristics. It describes:
1) Regular, circular, and doubly linked lists with their traversal directions.
2) The Node class which stores a node's data and next/prev pointers.
3) The Linkedlist class which contains a root node, size, and methods to add, find, remove and print nodes.
4) Circular linked lists which connect the last node to the first, allowing continuous looping.
This document summarizes different types of linked lists and their key characteristics. It describes:
1) Regular, circular, and doubly linked lists with their traversal directions.
2) The Node class which stores a node's data and next/prev pointers.
3) The Linkedlist class which contains a root node, size, and methods to add, find, remove and print nodes.
4) Circular linked lists which connect the last node to the first, allowing continuous looping.
LINKED LIST • find(data) • A Linkedlist object has two attributes: a root
• add(data) node that defaults to None, and a size node • remove(data) that defaults to 0. TYPES • print_list() • Add – create new node • Regular or Singly Linked List – It is transverse in one direction only • Find - iterate through the node until it finds • Circular Linked List – last node contain the the data passed in. NODE CLASS • Remove – delete node address of first node • Node class has a constructor that sets the • Print_List – iterate the list and print each • Doubly Linked List – Transversal is in forward as well as a backward direction data passed in and optionally can set the node next_node and prev_node LINKED LIST • It also has a str method to give a string representation for printing. CIRCULAR LINKED LIST • Every Node has 2 parts data and a pointer to the • Note: that prev_node is only used for • Advantage: over singly linked list next Node. doubly and circular linked list • Ideal for modeling continuous looping objects or data such as a monopoly or race track. class Node: def __init__(self, d, n=None, p=None): self.data = d self.next_node = n ATTRIBUTES self.prev_node = p • Includes attribute root and size. • Root – pointer to the beginning of the list • Includes methods add, find, remove and • Size – number of nodes in list def __str__(self): print_list. return ('('+ str(self.data) +')') DOUBLY LINKED LIST CIRCULAR LINKED LIST • Every Node has 3 parts: data and pointers to prev_node and next_node
• Advantage: over singly linked list
• Can iterate the list in either direction • Can delete a node without iterating through the list (if given a pointer to the node) LINKED LIST