Unhandled exception

I'm trying to write a code for sorting a link list. and I'm facing this error when I run the program and input data.Here's my code and the error "Unhandled exception: 0xC0000005: Access violation reading location 0x00000004" is for the bolded and underlined line:
#include<iostream>
using namespace std;
#include<conio.h>

struct node
{
int value;
struct node *link;
};

void sort(node**);

int main()
{
int tmp;
node *start,*p,*q;
cin>>tmp;
p=new node;
p->value=tmp;
start=p;
q=p;
while(cin>>tmp)
{
p=new node;
p->value=tmp;
q->link=p;
q=q->link;
}
q->link=NULL;
sort(&start);
p=start;
while(p)
{
cout<<
p->value<<',';
p=p->link;
}

getch();
return 0;
}

void sort(node **start)
{
int tmp,i=0,ind=0;
node *p,*q;
p=*start;
if((p->link))
{
tmp=p->value;
while(p->link)
{
if(p->value<tmp)
{
tmp=p->value;
ind=i;
}
i++;
p=p->link;
}
if(p->value<tmp)
{
tmp=p->value;
ind=i;
}
p=*start;
for(int j=0;j<--ind;j++)
p=p->link;
if(p==*start)
;
else
{
q=*start;
*start=p->link;
p->link=q;
}
sort(&((*start)->link));
}
}
try deleting one pair of () meaning instead of this

 
if((p->link))


try a change to this

 
if(p->link)


also could you post your in coding in code tags next time please?
Last edited on
Topic archived. No new replies allowed.