-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.cpp
More file actions
52 lines (51 loc) · 857 Bytes
/
LinkedList.cpp
File metadata and controls
52 lines (51 loc) · 857 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
49
50
51
52
#include <iostream>
using namespace std;
class node
{
public:
int key;
int data;
node *next;
node()
{
key = 0;
data = 0;
next = NULL;
}
node(int k, int d)
{
key = k;
data = d;
next = NULL;
}
};
void insertAthead(node *&head, int d)
{
node temp = new node(d);
temp->next = head;
head = temp;
}
void print(node *&head)
{
node *temp = head;
while (temp != NULL)
{
cout << temp->data;
temp = temp->next;
}
cout << endl;
}
int main()
{
node n1(1, 10);
node n2(2, 10);
node n3(3, 30);
// singlyLinkedList s(&n1);
// s.appendnode(&n2);
// s.prependnode(&n3);
node *node1 = new node(4, 40);
cout << node1->key << endl;
cout << node1->data << endl;
cout << node1->next << endl;
return 0;
}