满意答案
sotiq7294
2013.08.22
采纳率:45% 等级:12
已帮助:5605人
//create an orderedly single-liked list
template
void slist::insert_order(T item)
{ Node*currptr,*preptr,*newnode;
newnode=new Node(item, NULL); //prepare the inserted node
//find inserting positon
preptr=NULL;
currptr=head;
while(currptr!=NULL)
{ if (itemdata)
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
03分享举报