最近学了数据结构的单链表基本操作:创建,删除,插入,反转,排序等.
如有不当或错误之处,欢迎指正,不胜感激!
#include<stdio.h>
#include <malloc.h>
#include<stdlib.h>
int comp(const void *a,const void *b)//用于快排的比较函数
{
return (*(int*)a-*(int *)b);
}
struct node
{
int data;
struct node* next;
}Lnode;
struct node *p,*q;//声明临时节点
void head_insert(node &head,int x)//从头部插入新节点
{
p=(struct node*)malloc(sizeof(struct node));
if(p==NULL)
{
printf("内存申请失败,退出");
exit(0);
}
p->data=x;
p->next=head.next;
head.next=p;
}
void tail_insert(node &head,int x)//从尾部插入节点
{
p=(struct node*)malloc(sizeof(struct node));
if(p==NULL)
{
printf("内存申请失败,退出");
exit(0);
}
p-