Linked List : In computer science, a linked list is a linear collection of data elements, called nodes pointing to the next node by means of a pointer. It is a data structure consisting of a group of nodes which together represent a sequence.
Linked list elements are not stored at contiguous location; the elements are linked using pointers.
- Common Operation on Linked List are :
- checking whether the list is empty
- accessing a node to modify it or to obtain the information in it;
- traversing the list to access all elements (e.g., to print them, or to find some specific element);
- determining the size (i.e., the number of elements) of the list;
- inserting or removing a specific element (e.g., the first one, the last one, or one with a certain value);
- creating a list by reading the elements from an input stream;
- converting a list to and from an array, string, etc.
// A linked list node in C
struct node{ int data; struct node *next;};// A linked list node in Java class Node { int data; Node next; // Constructor to create a new node // Next is by default initialized as null Node(int d) {data = d;} }# Node class in Python
class Node: # Function to initialize the node object def __init__(self, data): self.data = data # Assign data self.next = None # Initialize next as null
No comments:
Post a Comment