-
Notifications
You must be signed in to change notification settings - Fork 0
/
IAFP.CPP
115 lines (91 loc) · 1.64 KB
/
IAFP.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
struct node //defination of struture
{
int data;
node *prev;
node *next;
} ;
node *create() //node creation
{ node * newn ;
newn = (node *) malloc(sizeof(node)) ;
newn->next=NULL;
newn->prev=NULL;
return(newn);
}
/* ****** funtion declartions ********* */
void input();
void display();
void revdisplay();
void insert();
node *head=NULL;
node *start=NULL;
node *end=NULL;
void input()
{
node *in,*trav,*t;
in=create();
cout<<"enter the data ";
cin>>in->data ;
if(head==NULL)
{
head=in;
start=in;
}
else
in->prev=head;
head->next=in;
head=in;
end=head;
}
void display()
{ int a=0;
node * prnt;
prnt=start;
while(prnt->next!=NULL)
{
cout<<prnt->data<<endl;
prnt=prnt->next;
if(a>10){break;}a++;
}
cout<<prnt->data;
}
void revdisplay()
{ int a=0;
node * prnt;
prnt=end;
while(prnt->prev!=NULL)
{
cout<<prnt->data<<endl;
prnt=prnt->prev;
if(a>10){break;}a++;
}
cout<<prnt->data;
}
void insert()
{
node *first;
first=create();
cout<<"\nenter the data ";
cin>>first->data;
start->prev=first;
first->next=start;
first->prev=NULL;
start=first;
}
void main()
{
int ele,i;
clrscr();
cout<<"enter the no of nodes you want ";
cin>>ele;
for(i=0;i<ele;i++)
{
input();
}
display();
insert();
display();
getch();
}