-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLINK2.CPP
68 lines (65 loc) · 1.27 KB
/
LINK2.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
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct Node
{
int info;
Node* next;
}*start, *newptr, *save, *ptr, *rear;
Node *Create_New_Node (int);
void Insert_Beg (Node*);
void Display (Node*);
void main()
{
start = rear = NULL;
int inf; char ch='y';
while (ch=='y'||ch=='Y')
{
clrscr();
cout<<"\nEnter INFOrmation for the new node...";
cin>>inf;
cout<<"\nCreating new node. Press enter to continue...";
getch();
newptr=Create_New_Node(inf);
if (newptr!=NULL)
{ cout<<"\n\nNew node created successfully. Press enter to continue";
getch();
}
else
{
cout<<"\nCannot create new node!!! Aborting!!\n";
getch();
exit(1);
}
cout<<"\n\nNow inserting this node in the ebd of list...\n";
cout<<"press enter to continue...";
getch();
Insert_Beg(newptr);
cout<<"\nNow the list is:\n";
Display(start);
cout<<"\nPress Y to enter more nodes, N to exit...\n";
cin>>ch;
}
}
Node* Create_New_Node (int n)
{ ptr=new Node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void Insert_Beg (Node* np)
{ if (start==NULL) start=rear=np;
else
{
rear->next=np;
rear=np;
}
}
void Display (Node* np)
{ while (np!=NULL)
{
cout<<np->info<<"->";
np=np->next;
}
cout<<"!!!\n";
}