R
raghu
I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler
#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node *link;
};
void main()
{
int num=10;
struct node *p;
p=NULL;
append(&p,num);
getch();
}
struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p->data=num;
p->link=NULL;
return p;
}
append(struct node **q,int num)
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
}
return 0;
}
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler
#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node *link;
};
void main()
{
int num=10;
struct node *p;
p=NULL;
append(&p,num);
getch();
}
struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p->data=num;
p->link=NULL;
return p;
}
append(struct node **q,int num)
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
}
return 0;
}