#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include<conio.h>
#include<iostream>
struct list
{
int data;
struct list *next;
}*L;
//function declaration:
void create(int data,struct list **head);
void print(struct list **head);
int main()
{
//list *L;
int data =10;
for(int i=0;i<3;i++)
{
//struct list *pList = NULL;
create(data++,&L);
print(&L);
getch();
}
}
void create(int data,list **head)
{
list *pNew = new list;
if (*head==NULL)
{
(*head)->next=NULL;
(*head)->data=data;
//(**head).data=info;
//pNew->data =data;
//pNew->next=*head;
}
else
{
pNew =*head;
while(pNew!=NULL)
{
//*head=(**head).next;
pNew=pNew->next;
}
list *temp =new list;
temp->data=data;
temp->next=NULL;
pNew->next =temp;
//(**head).next=(**head).next;
}
//return 0;
}
void print(list **head)
{
list *temp1 = new list;
temp1 =*head;
while( temp1!=NULL )
{
std::cout<< temp1->data<<" ";// show the data in the linked list
temp1 = temp1->next; // tranfer the address of 'temp->next' to 'temp'
}
}
Hello Guys,
I am a bit rusty on pointers,i actually want to implement linked list ,but my compiler is giving error.
i am getting run time error at line
(head)->next=NULL;
(head)->data=data;
Would be great if someone can review the short snippet code and point my mistake.
Any other suggestions are always welcome.
Please note that i have also tried using (**head).data=data; but then also i am still getting runtime error .
i am not sure how to proceeed next.