In c++: create an algorithm to convert the 2D matrix into a linked list.
what is the BigO of the algorithm?
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include <iostream>
#include<cstdlib>
using namespace std;
// struct node of linked list
struct node {
int data;
node *right, *down;
};
// utility function to create a new node with given
data
node* newNode(int d)
{
node* temp = new node;
temp->data = d;
temp->right = temp->down = NULL;
return temp;
}
// utility function to print the linked list pointed to by
head pointer
void display(node* head)
{
node *rp, *dp = head;
// loop until the down pointer is not NULL
while (dp) {
rp = dp;
// loop until the right pointer is not NULL
while (rp) {
cout << rp->data << " ";
rp = rp->right;
}
cout << endl;
dp = dp->down;
}
}
// function which constructs the linked list
// from the given matrix of size m * n
// and returns the head pointer of the linked list
node* constructLinkedMatrix(int mat[][3], int m, int n)
{
// stores the head of the linked list
node* mainhead = NULL;
// stores the head of linked lists of each row
node* head[m];
node *righttemp, *newptr;
// Firstly, we create m linked lists
// by setting all the right nodes of every row
for (int i = 0; i < m; i++) {
// initially set the head of ith row as NULL
head[i] = NULL;
for (int j = 0; j < n; j++) {
newptr = newNode(mat[i][j]);
// stores the mat[0][0] node as
// the mainhead of the linked list
if (!mainhead)
mainhead = newptr;
if (!head[i])
head[i] = newptr;
else
righttemp->right = newptr;
righttemp = newptr;
}
}
// Then, for every ith and (i+1)th list,
// we set the down pointers of
// every node of ith list
// with its corresponding
// node of (i+1)th list
for (int i = 0; i < m - 1; i++) {
node *temp1 = head[i], *temp2 = head[i + 1];
while (temp1 && temp2) {
temp1->down = temp2;
temp1 = temp1->right;
temp2 = temp2->right;
}
}
// return the mainhead pointer of the linked list
return mainhead;
}
// Driver program to test the above function
int main()
{
int m, n; // m = rows and n = columns
m = 3, n = 3;
// 2D matrix
int mat[][3] = { { 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 } };
node* head = constructLinkedMatrix(mat, m, n);
display(head);
return 0;
}

Time complexity of the above algorithm in cpp is O(M * N) where M is number of rows and N is number of cols.
Kindly revert for any queries
Thanks.
In c++: create an algorithm to convert the 2D matrix into a linked list. what is...
c++ question. implementing linked list how would you create the bellman-ford algorithm for weighted graphs?
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...
write any 2 c functions for a linked list and a doubly-linked sorted list create at least two data structures
write an algorithm (algorithm appendToItself(pList)) that appends a list to itself, using linked-list implementation [hint: you may want to utilize insertNode algorithm we developed in the class together]. The desired language is C.
C++ function using templates and linked list. [Create a simple linked list class to use within the class queue.] template <class T> class Queue : linkedList { void EnqueueO1(T t) - adds t to the end of the queue. };
In C++ Create a data structure doubly linked list, implement the following operations for the doubly linked list: addFirst addLast insertBefore insertAfter delete printList
in c++ Create a circular, doubly linked list from a file (input.txt), containing a list of names. The number of names is unknown. Prompt the user for the number of nodes to delete and then delete accordingly from the list. Assumption: The number inputted by the user will not exceed the actual number of nodes in the list.
Using Python Create a simple linked list by defining a struct (in C/C++) or a class (in Python3). For example, in C/C++: struct singly_linked_list { int data; singly_linked_list *next; }; (Make sure you understand the concept of pointers - or lack thereof - in Python.) Write a function to determine if there is a cycle in the singly linked list. Return 1 if there is a cycle in the list, 0 if no cycle. This is a very common interview...
write the java code to convert a linked list of integers, to a stack of integers. thus your code will traverse the linked listand populate the stsck. linked list 1->2->3. becomes stack 3 First Last 2 1
Describe a parallel algorithm for computing the minimum for n numbers on a linked list.