Skip to content

Commit 5e3813e

Browse files
Printing Singly Linked List
1 parent 0bf48a0 commit 5e3813e

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

output.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
10
22
20
3+
30
4+
40
5+
50
6+
------------------
7+
Line Break
8+
------------------
9+
10
310
20
4-
20
11+
30
12+
40
13+
50

print_linked_list.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Node
5+
{
6+
public:
7+
int val;
8+
Node *next;
9+
10+
Node(int val)
11+
{
12+
this->val = val;
13+
this->next = NULL;
14+
}
15+
};
16+
17+
int main()
18+
{
19+
Node *head = new Node(10);
20+
Node *a = new Node(20);
21+
Node *b = new Node(30);
22+
Node *c = new Node(40);
23+
Node *d = new Node(50);
24+
25+
head->next = a;
26+
a->next = b;
27+
b->next = c;
28+
c->next = d;
29+
30+
/* cout << head->val << endl;
31+
cout << head->next->val << endl;
32+
cout << head->next->next->val << endl; */
33+
34+
Node *tmp = head;
35+
36+
while (tmp != NULL)
37+
{
38+
cout << tmp->val << endl;
39+
tmp = tmp->next;
40+
}
41+
cout << "------------------" << endl
42+
<< "Line Break"
43+
<< endl
44+
<< "------------------" << endl;
45+
tmp = head;
46+
while (tmp != NULL)
47+
{
48+
cout << tmp->val << endl;
49+
tmp = tmp->next;
50+
}
51+
52+
return 0;
53+
}

print_linked_list.exe

51.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)