Concept explainers
Explanation of Solution
The function for concatenating two linked lists:
The function to concatenate two linked is dined as below.
//Define method concatenate
static void concatenate(node *a, node *b)
{
//If condition satisfies
if( a != NULL && b!= NULL )
{
//If condition satisfies
if (a->nxt == NULL)
//Assign value
a->nxt = b;
//If condition satisfies
else
//Call method
concatenate(a->nxt,b);
}
//If condition satisfies
else
{
//Display message
cout << "Either a or b is NULL\n";
}
}
Explanation:
- The function “concatenate()” concatenates values in two linked lists.
- It checks initially whether two linked lists are empty or not.
- If both linked lists are non-empty, it proceeds with checking the end of first linked list.
- Assign second linked list to the end of first linked list.
- The result is been displayed finally.
Complete Program:
//Include library
#include <iostream>
//Use namespace
using namespace std;
//Define structure
struct node
{
//Declare variable
int dta;
//Declare pointer
node *nxt;
};
//Define class
class lnkdLst
{
//Define access specifier
private:
//Define nodes
node *head,*tail;
//Define access specifier
public:
//Define constructor
lnkdLst()
{
//Assign value
head = NULL;
//Assign value
tail = NULL;
}
//Define method
void AdNode(int n)
{
//Assign value
node *tmp = new node;
//Assign value
tmp->dta = n;
//Assign value
tmp->nxt = NULL;
//If condition satisfies
if(head == NULL)
{
//Assign value
head = tmp;
//Assign value
tail = tmp;
}
//If condition satisfies
else
{
//Assign value
...Trending nowThis is a popular solution!
Chapter 8 Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- How is an array stored in main memory? How is a linked list stored in main memory? What are their comparative advantages and disadvantages? Give examples of data that would be best stored as an array and as a linked list.arrow_forwardFrom page 147, #25: Design and implement an experiment that will compare the performance of a Python list with a list implmentd as a linked listarrow_forwardin c++, Deallocating memory pointed to by the head of a Linked List always deallocates the memory used by whole Linked List, True or False?arrow_forward
- 8) Write a menu-driven program to create an unrolled linked list and retrieve, insert and delete an element from it. You may take liberties with the operations while implementing them.arrow_forwardIs it possible to implement a sorted linked list with a DLL? What advantage a DLL implementation may have over a singly linked list? Use a specific example or application to support your argument.arrow_forwardAre linked lists considered linear or non-linear data structures?arrow_forward
- 1-Write a C++ Function that returns the data of the middle node in a linked list and in case the linked list contains only one node return the data inside this node and returns the sum of all the nodes in linked list and returns the maximum data value in the linked listarrow_forwardWhat are the distinctions between arrays and linked lists?arrow_forwardWrite a C program to perform following operations on Single LinkedList: Create() - Create a Single Linked list with 8 Nodes Insert() - Insert a node in the ending OddDisplay () - Display only those Nodes which has Odd Value and sum it Count() - Count the length of the Linkedlist Note: It must be a menu-driven program and User defined functions must be there for all the functionalities.arrow_forward
- Write a structure that is to be used in a single-linked list. The structure should hold the name and addresses of your friends.arrow_forwardA linked list is a data structure that has sequence of nodes where every node is connected to the next node by means of a reference pointer. Are linked lists of linear or non-linear type? EXPLAIN by your own wordsarrow_forwardC Language Explain what is the difference between a doubly linked list and singly linked list? Give the advantages and uses of a circular linked list. Thank youarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning