-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsinglylinkedlist_structure.cpp
63 lines (52 loc) · 1.08 KB
/
singlylinkedlist_structure.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
54
55
56
57
58
59
60
61
62
63
#include <iostream>
using namespace std;
struct node
{
int data;
struct node *nxt_ptr;
};
void firstapppend(struct node **head, int x)
{
struct node *n1 = new struct node();
n1->data = x;
n1->nxt_ptr = NULL;
*head = n1;
}
void preappend(struct node **head, int x)
{
struct node *n1 = new struct node();
struct node *temp = *head;
n1->nxt_ptr = temp;
*head = n1;
n1->data = x;
}
void append(struct node **head, int x)
{
struct node *temp = *head;
struct node *n2 = new struct node();
while (temp->nxt_ptr != NULL)
{
temp = temp->nxt_ptr;
}
temp->nxt_ptr = n2;
n2->data = x;
n2->nxt_ptr = NULL;
}
void display(struct node **head)
{
struct node *temp = *head;
while (temp != NULL)
{
cout << temp->data << "->";
temp = temp->nxt_ptr;
}
}
int main()
{
struct node *head = new struct node();
head->nxt_ptr = NULL;
firstapppend(&head, 8);
preappend(&head, 0);
append(&head, 10);
display(&head);
}