Explain linked list using C++ with an example?
Submitted by: AdministratorA linked list is a chain of nodes. Each and every node has at least two nodes, one is the data and other is the link to the next node. These linked lists are known as single linked lists as they have only one pointer to point to the next node. If a linked list has two nodes, one is to point to the previous node and the other is to point to the next node, then the linked list is known as doubly linked list.
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;
}
Submitted by: Administrator
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;
}
Submitted by: Administrator
Read Online Data Structure Linked list Job Interview Questions And Answers
Top Data Structure Linked list Questions
☺ | Suppose In an integer array, there is 1 to 100 number, out of one is duplicate, how to find? |
☺ | What is circular linked list? |
☺ | Explain linked list using C++ with an example? |
☺ | Explain the steps to insert data into a singly linked list? |
☺ | Explain how to find 3rd element from end in a linked list in one pass? |
Top Data Structure Categories
☺ | Data Center Manager Interview Questions. |
☺ | Creative UI/UX Designers Interview Questions. |
☺ | Sort And Searching Interview Questions. |
☺ | Data Structure Linked list Interview Questions. |
☺ | Data Structure Arrays Interview Questions. |