0% found this document useful (0 votes)
46 views2 pages

Link List Using Array

Uploaded by

abxrnt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views2 pages

Link List Using Array

Uploaded by

abxrnt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;

// Structure of Linked Lists


struct info {
int data;
info* next;
};

// Driver Code
int main()
{
int size = 10;

// Pointer To Pointer Array


info** head;

// Array of pointers to info struct


// of size
head = new info*[size];

// Initialize pointer array to NULL


for (int i = 0; i < size; ++i) {
*(head + i) = NULL;
}

// Traverse the pointer array


for (int i = 0; i < size; ++i) {

// To track last node of the list


info* prev = NULL;

// Randomly taking 4 nodes in each


// linked list
int s = 4;

while (s--) {

// Create a new node


info* n = new info;

// Input the random data


n->data = i * s;
n->next = NULL;

// If the node is first


if (*(head + i) == NULL) {
*(head + i) = n;
}
else {
prev->next = n;
}
prev = n;
}
}

// Print the array of linked list


for (int i = 0; i < size; ++i) {
info* temp = *(head + i);
// Linked list number
cout << i << "-->\t";

// Print the Linked List


while (temp != NULL) {
cout << temp->data << " ";
temp = temp->next;
}

cout << '\n';


}

return 0;
}

OUTPUT:

0--> 0 0 0 0
1--> 3 2 1 0
2--> 6 4 2 0
3--> 9 6 3 0
4--> 12 8 4 0
5--> 15 10 5 0
6--> 18 12 6 0
7--> 21 14 7 0
8--> 24 16 8 0
9--> 27 18 9 0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy