Archive for the ‘Data Structures in C/C++’ Category

Swapping nodes in a single linked list

Here is algorithm for swapping two nodes in linked list..

//A complete swap algorithm which cares of
//several scenarios while swapping two nodes in
//a linked list which doesn’t have any special nodes
//scenarios considered while swapping
//1)two nodes which are far away
//2)two nodes which are far away, one is node is at
// beginning of the list
//3)two node which [...]

Continue Reading..
Posted in C Tidbits, Data Structures in C/C++

Printing Binary Trees in Ascii

Here we are not going to discuss what binary trees are (please refer this, if you are looking for binary search trees), or their operations but printing them in ascii.
The below routine prints tree in ascii for a given Tree representation which contains list of nodes, and node structure is this

struct Tree
{
Tree * [...]

Continue Reading..
Posted in C Tidbits, Data Structures in C/C++

Circular Linked Lists

Please visit my earlier post linked lists for basics of linked lists. Visit this post for circular double linked lists
What is circular linked list?
Circular Linked lists are chain of records/nodes, one record/node points to the next, and last node/record pointing to the first node instead of pointing to a sentinel. Record/node holds the data.
Why circular [...]

Continue Reading..
Posted in Uncategorized