Error in code Insertion in the begining of list

This is the code for insertion in the beginning of the list.


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
  #include<iostream.h>
#include<process.h>
#include<conio.h>
struct node
{
int info;
node *next;
node *start,*newptr,*save,*ptr;
}
node * createnewnode(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void insert_beg(node* np)
{
if (start==NULL)
start=np;
else
{
save=start;
start=np;
np->next=save;
}
}
void display(node *np)
{
while (np!=NULL)
{
cout<<np->info<<"->";
np=np->next;
}
cout<<"!!!\n";
}
void main ()
{
start=NULL;
int nf;
char ch='y';
while (ch='y'||ch='Y')
{
clrscr();
cout<<"First entry:"<<inf;
newptr=createnewnode(inf);
if(newptr!=NULL)
{
cout<<"Node creation succesful.Press enter to continue...";
system("pause");
}else
{
cout<<"Cannot create a new node.Abort Mission!!..." ;
exit(1);
}
insert_beg(newptr);
cout<<"\nnow the list is :\n";
display(start);
cout<<"\n press y to enter more nodes, N to exit...\n";
cin>>ch;
}
getch();
}



The compiler is giving 1 error saying that there is an error at line 10: declaration syntax error
How do i fix this?
Last edited on
The compiler is giving 1 error saying that there is an error at line 10: declaration syntax error
How do i fix this?


Fix line 9. With a semicolon at the end.

Please use indentation. And standard C++.
Topic archived. No new replies allowed.