-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateLinkedList.cpp
More file actions
68 lines (62 loc) · 1.28 KB
/
createLinkedList.cpp
File metadata and controls
68 lines (62 loc) · 1.28 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
struct cellule
{
int info;
struct cellule* suivant;
};
typedef struct cellule* pointeur;
pointeur createFromBack(int[], int);
void dispVec(int[], int);
void dispLinkedList(pointeur);
int main()
{
int size = -1;
int* tab;
pointeur l;
do
{
cout << "Enter the size of the linked list: ";
cin >> size;
} while (size < 0);
tab = new int[size];
cout << "Enter the values on the vector!!!" << endl;
for(int i=0;i<size;i++)
{
cout << "Position " << i+1 << ": ";
cin >> tab[i];
cin.ignore();
}
cout << "Here are your values in your vector: " << endl;
dispVec(tab,size);
cout << "\nMapping datas to the linked list.........." << endl;
l = createFromBack(tab,size);
dispLinkedList(l);
cout << "\nEnd of program...";
delete[] tab;
}
pointeur createFromBack(int v[], int n)
{
pointeur l;
l=nullptr;
for(int i=0;i<n;i++)
{
pointeur p;
p->info = v[i];
p->suivant = l;
l=p;
}
return l;
}
void dispLinkedList(pointeur l)
{
while(l->suivant != nullptr)
{
cout << l->info << " ";
l = l->suivant;
}
}
void dispVec(int v[], int n)
{
for(int i=0;i<n;i++) cout << v[i] << " ";
}