-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_List.cpp
More file actions
53 lines (51 loc) · 1018 Bytes
/
linked_List.cpp
File metadata and controls
53 lines (51 loc) · 1018 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
53
#include<iostream>
using namespace std;
struct node{
int data;
struct node * next;
}*head=NULL;
typedef struct node N;
void insert(int num){
N *temp;
temp=(N *)malloc(sizeof(N*));
temp->data=num;
temp->next=NULL;
if(head==NULL)
head=temp;
else{
N *t;
t=head;
while(t->next!=NULL)
t=t->next;
t->next=temp;
cout<<t->data<<" Num : "<<num<<endl;
}
}
void insert_at_begin(int num){
N *temp;
temp=(N *)malloc(sizeof(N*));
temp->data=num;
if(head==NULL)
temp=head;
else
temp->next=head;
head=temp;
}
void insert_at_end(int num){
insert(num);
}
int main(){
insert(4);
insert(7);
insert(8);
insert_at_begin(6);
insert_at_end(7);
N *t;
t=head;
cout<<"list\n";
while(t!=NULL){
cout<<t->data<<" --> ";
t=t->next;
}
cout<<"NULL";
}