struct node{
int data;
struct node* next;
};
前置插入
void insertNewNode(struct node* headPos,int data){
struct node* newNodePos = (struct node*)malloc(sizeof(struct node*));
(*newNodePos).data = data;
newNodePos->next = (*headPos).next;
(*headPos).next = newNodePos;
}
后置插入
void myinsertTail(struct node * headPos , int insData ){
struct node* p = (struct node*)malloc(sizeof(struct node*));
p->data = insData;
p->next = NULL;
struct node* q;
q = headPos;
while(q->next!=NULL)
q = q->next;
q->next = p ;
打印函数
void myprintList(struct node *L){
struct node* p = L;
while(p->next != NULL)
{
p=p->next;
printf("%d\n",p->data);
}
}
主函数
int main(){
struct node head;
head.data = -1;
head.next = NULL;
myinsertTail(&head,3);
myinsertTail(&head,4);
myinsertTail(&head,5);
myprintList(&head);
return 0;
}