//create an orderedly single-liked list
template
void slist
{ Node
newnode=new Node
//find inserting positon
preptr=NULL;
currptr=head;
while(currptr!=NULL)
{ if (item
break;
preptr=currptr;
currptr=currptr->next;
}
//make the insertion
if(preptr==NULL) //insert into the head of the linked list
{ newnode->next=head;
head=newnode;
else //insert into middle of the linked list
{ newnode->next=currptr;
preptr->next=newnode;
//newnode相當於你提問的x
//create an orderedly single-liked list
template
void slist
{ Node
newnode=new Node
//find inserting positon
preptr=NULL;
currptr=head;
while(currptr!=NULL)
{ if (item
break;
preptr=currptr;
currptr=currptr->next;
}
//make the insertion
if(preptr==NULL) //insert into the head of the linked list
{ newnode->next=head;
head=newnode;
}
else //insert into middle of the linked list
{ newnode->next=currptr;
preptr->next=newnode;
}
}
//newnode相當於你提問的x