You have to check these, 3 condition first-:
1.) If list 1 is empty or not.
o> If list 1 is empty then concatenated list will be list 2 only.
2.) If list 2 is empty or not.
o>If list 2 is empty than concatenated list will be list 1 only.
3. If both lists are empty or not.
o>concatenated list will be empty list.
Suppose that our two lists are non-empty linked list, list 1 has start_1 pointer as head pointer and list 2 has start_2 as head pointer.
TO CONCATENATE THE 2 NON-EMPTY LISTS WE NEED TO FOLLOW BELOW STEPS-:
1. Make a pointer 'p' which point to start_1.
2. Take that pointer to last element(node) of list 1 which contains address as NULL.
3. Store the address of first element of list 2 in address field of last node of list 1.
Now you are ready with your concatenated list;)
Algorithm to concatenate 2 linked list-:
node * concatenate (node *start_1, node *start_2)
{
node*p;
if (start_1==NULL) //if the first linked list is empty
return(start_2);
if (start_2==NULL) //if second linked list is empty
return (start_1);
p=start_1; //place p on the first node of the first linked list
while (p->next!=NULL) //move p to the last node
p=p->next;
p->next=start_2; //address of the first node of the second linked list stored in the last node of the first linked list return(start_1);
}
C++ CODE
OUTPUT
Hello, how do I create a new singly linked list by concatenating two existing singly linked...
Q.(1)Describe the algorithm and java implementation for the following operations A. Create a singly linked list L1 with 4 nodes. You can use insert operation to add nodes to the list. Each element represent an airport code (e.g. BOS, ATL, JFK, MSP, etc.). Display the list L1 after it is created. B. Given singly linked list L1, create another singly linked list L2 that contains the same elements but in the reverse order. Display the content of both L1 and...
How do you implement a stack using a singly linked list in Java? Can you make it a simple implementation with just push and pop methods.
[C++] Create three functions for a singly linked list: - Function 1: Insert a string into the linked list - Function 1: Insert a node after a given node (Node* curNodeptr, Node* newNodePtr) - Function 2: Delete the node passed to it by a pointer, it will take in the head and curPtr '(Node*, Node*)' struct Node{ string data; Node *next; };
IMPLEMENT AN IMMUTABLE SINGLY LINKED LIST IN JAVASCRIPT ------------------------------------------------------------------------------------------------------------------------- So I am trying to implement a singly linked list that given the below function will pass the bottom four tests when ran. Please help me generate the singly linked list that will work and pass the tests. I will only use this as a reference so please add comments to explain what you are doing so I can understand and write this myself. I think a join method may need...
Programing C Just with #include <stdio.h> We will create a singly linked list of 7 nodes. Then, the user will tell us whether to print the “odd-placed” nodes or the “even-placed” nodes. For example, if I had a list of 5 nodes like below, and the user specifies for the odd nodes to be printed, my program would print the values in nodes nl and n3. If the user instead indicated for the even nodes to be printed, my program...
how to implement a linked list object using only singly linked list toolkit. Then implement a FREQUENCY function to count the ovcurrence of each element in the list. task#1: Add = operator to node: implement the assignment operator for the node such that setting a node = overwrites the value in the node with the value. task#2:Linked List class implement the methods of linked list. insert search and locate remove node* operator [] task#3: Implement the Frequency
If If you have a normal singly linked list, how could you print the items backward?
Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...
I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas. public class Node ! int id; Node next: public Node (int id) ( this.id id: Write program codes for the traditional: 1) append int id), prepend(int id), removeFirstNodeO. displayAlINodesO, and findById(int id) operations for a singly linked list 2) pushint id), pop), peek0, displayAllNodes0 operations for a stack 3) enQueue(int id), deQueuel), displayAINodes() operations for a gueue Please make sure that you declare separate...
// Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. // the variable: back "points" at the first node in the linked list // new elements ( enqueued) are added at the back // the variable: front "points" at the last node in the linked list. // elements are removed (dequeued) from the front // // Several queue instance methods are provided for you; do not change these // Other instance methods are left for...