Data Structure Linked list Question:
Download Questions PDF

By using C++ with an example describe linked list?

Linked list Interview Question
Linked list Interview Question

Answer:

To use a linked list in C++ the following structure is to be declared:

typedef struct List
{long Data;
List* Next;
List ()
{Next=NULL;
Data=0;
}
};
typedef List* ListPtr.

The following code snippet is used to add a node.

void SLList::AddANode()
{ListPtr->Next = new List;
ListPtr=ListPtr->Next;
}

The following code snippet is used to traverse the list

void showList(ListPtr listPtr)
{
while(listPtr!=NULL) {
cout<<listPtr->Data;
}
return temp;
}

Download Linked list Interview Questions And Answers PDF

Previous QuestionNext Question
What is linked list?Do you know what does the following function do for a given Linked List?