forked from PiyushYadav007/Portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertion_at_beginning000004.cpp
More file actions
49 lines (41 loc) · 994 Bytes
/
insertion_at_beginning000004.cpp
File metadata and controls
49 lines (41 loc) · 994 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
#include <iostream>
#include <stdlib.h>
using namespace std;
struct node
{
int data;
struct node *next;
};
void trivarsal(struct node *ptr)
{
while (ptr != NULL)
{
cout << "Element are :- " << ptr->data << endl;
ptr = ptr->next;
}
}
struct node *InsertAtfirst(struct node *head , int data){
struct node *ptr=(struct node *)malloc(sizeof(struct node));
ptr->next=head;
ptr->data=data;
return ptr;
}
int main()
{
struct node *head;
struct node *second;
struct node *third;
head = (struct node *)malloc(sizeof(struct node));
second = (struct node *)malloc(sizeof(struct node));
third = (struct node *)malloc(sizeof(struct node));
head->data = 34;
head->next = second;
second->data = 235;
second->next = third;
third->data = 354;
third->next = NULL;
trivarsal(head);
head=InsertAtfirst(head,22);
trivarsal(head);
return 0;
}