-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkListArrayPass.cpp
More file actions
48 lines (43 loc) · 955 Bytes
/
Copy pathLinkListArrayPass.cpp
File metadata and controls
48 lines (43 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include <stdlib.h>
using namespace std;
struct Node* creatLinkList(int arr[], int size);
struct Node
{
int data;
struct Node* next;
};
int main()
{
int a[] = { 5, 10, 15, 20, 30, 1000000 };
struct Node* head;
head = creatLinkList(a, 6);
while (head != NULL)
{
cout << head->data<<" ";
head = head->next;
}
cout << endl;
return 0;
}
struct Node *creatLinkList(int arr[], int size)
{
struct Node *head = NULL, *temp = NULL, *current = NULL;
for (int i = 0; i<size; i++)
{
temp = (struct Node*)malloc(sizeof(struct Node));
temp->data = arr[i];
temp->next = NULL;
if (head == NULL)
{
head = temp;
current = temp;
}
else
{
current-> next = temp;
current = current-> next;
}
}
return head;
}