In this case the condition (start=NULL) will be satisfied. First case when there is not even a single node in the list(list is empty).The insertion of node at the end of singly linked list can have two cases: Start=p //new node 'p' will become the first node of the list P=(struct node *) malloc(sizeof(struct node)) After that we will make new node as the first node(start).Now we will point the link part of the new node with the first node(start) of existing linked list.First we will create a new node and store the data into the data part.In this a new node is inserted in the front of already existing linked list. ![]() The insertion of node in singly linked list can be performed at different positions. The insertion operation in linked list is used to insert the new node. The data part of the node holds the value/element and link part of the node holds the address of its immediate successor. Singly Linked list is also known as one way list list in which we can traverse only in forward/one direction because a node in singly linked list contains a data part and a link part. It uses more memory because each node contains a pointer and it requires extra memory for itself.If we want to access any node randomly, then we have to traverse all the nodes before it. Traversal is difficult in linked list.Data structures such as stack, queue can be implemented easily.The operations like insertion, deletion of nodes are easy as compared to that of array.As the memory is allocated or deallocated during runtime so there is no memory wastage.Linked list is a dynamic data structure so it can grow or shrink during runtime by allocating and deallocating memory.P is a pointer variable which is used to create memory block in RAM. Struct node * start defines start as a variable which can store the address of the node. Struct node * next is the pointer variable of node datatype. Int data is the data part of the node which will hold the data. ![]() Here, we've created a structure of a node. P=(struct node*)malloc(sizeof(struct node)) So we will create a structure using struct keyword. Structure of a nodeĪs we know that a node contains data part and link part. We have create a Node structure in C and implemented all Linked List operations in C. In this article, we have designed and implemented Linked List in C Programming Language.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |