Data Structures

Finding a circular loop in a linked list

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures

There are several ways to find out if a loop is present in the linked list or not. Let’s look at the two ways: 1) If we can modify the linked list structure, then insert a Boolen (bool) flag called visited in the structure. Start traversing the linked list, on every node mark the flag visit […]

Program to find the middle of a linked list

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; /* Function to find the middle node for the linked list, given the starting node pointer*/ struct list* middle(struct list* head) {

Program to remove duplicates from a linked list

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; #define FREE(x) free(x);x=NULL; /* Function to remove duplicates from a linked list, given the head pointer for the list*/ void removeDuplicates(struct list** head) {

Program to split a linked list from a given position

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; /* Function to split a linked list into two parts, given the position from which to start splitting*/ void split(struct list* head, struct list** dest, int position) {

Program to delete a node from a linked list

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; #define FREE(x) free(x);x=NULL; /* Function to delete a node from a linked list, given the value for the node*/ int delete(struct list** head, int value) {

Program to find length of linked list using Recursion

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; /* Function to find the length of linked list using recursion, given the starting node pointer*/ int length(struct list* node) {

Program to print linked list in reverse order using Recursion

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; /* Function to print data in reverse order for a linked list, given the starting node pointer*/ void reverseprint(struct list* node) {

Program to traverse the linked list

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; /* Function to traverse the linked list given the starting node pointer */ void traverse(struct list* node) {

Program to insert a node in the linked list

August 29th, 2009  |  by  |  published in Amit Sahrawat, Data Structures, Linux Sample Programs

/* Structure for a linked list*/ struct list{     int num;     struct list* next; /* pointer to next node in list*/ }; /* Function to insert node into a linked list, given the head pointer and the value to be inserted */ void insert(struct list **head,int value) {

Subscribe

Get articles in your inbox.

Enter your email address:

Join Us

Twitter Chatter


Recommendations

Archives

Categories