-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollie48.cpp
53 lines (47 loc) · 1.14 KB
/
ollie48.cpp
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
#include<iostream>
using namespace std;
// LINKED LIST CREATION AND TRAVERSAL REVISITED.
struct Node
{
int data;
struct Node* next;
};
void linkedlisttraversal(struct Node* ptr)
{
while(ptr != NULL)
{
//cout<<"Element: "<<(*ptr).data<<endl;
cout<<"Element: "<<ptr->data<<endl;
//ptr = (*ptr).next;
ptr = ptr->next;
}
}
int main()
{
struct Node* head;
struct Node* second;
struct Node* third;
struct Node* fourth;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
fourth = (struct Node*)malloc(sizeof(struct Node));
//(*head).data = 13;
head->data = 13;
//(*head).next = second;
head->next = second;
//(*second).data = 17;
second->data = 17;
//(*second).next = third;
second->next = third;
//(*third).data = 19;
third->data = 19;
//(*third).next = NULL;
third->next = fourth;
//(*fourth).data = 23;
fourth->data = 23;
//(*fourth).next = NULL;
fourth->next = NULL;
linkedlisttraversal(head);
return 0;
}