MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / createList

Function createList

CPP/LINKED LIST/Linked_list.cpp:12–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10// initialised first as null
11
12void createList(int arr[], int n)
13{
14 struct Node *t;
15 struct Node *last;
16
17 // setup a new node
18 first = new struct Node;
19 first->data = arr[0];
20 first->next = NULL;
21
22 // last is first as 1 element only
23 last = first;
24
25 for (int i = 1; i < n; i++)
26 {
27 // setup a new node
28 t = new struct Node;
29 t->data = arr[i];
30 t->next = NULL;
31
32 // make current last point to new node
33 last->next = t;
34
35 // update last
36 last = t;
37 }
38};
39
40void printList(struct Node *p)
41{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected