作为一名通工转cs的coder,这学期中终于开始学习数据结构,在此做一些学习总结,以下是实现的一些功能:
- 建立链表
- 求链表长度
- 打印数据
- 按序号查找
- 按值查找
- 单链表的插入,按序号插入
- 删除链表第i个元素
- 倒置链表
- 单链表中删除重复节点,排序思想,双重循环进行比较
冒泡排序
定义结构体
struct node
{
int num;
struct node *next;
};
typedef struct node *LinkList,Node;
建立链表
LinkList create_LinkList();
LinkList create_LinkList()
{
LinkList h=(LinkList)malloc(sizeof(Node));
h->next=NULL;
Node *s,*r=h;
int x;
scanf("%d",&x);
while(x!=-1)
{
s=(LinkList)malloc(sizeof(Node));
s->num=x;
r->next=s;
r=s;
//s->next=r->next;
//r->next=s;
//r=s;
scanf("%d",&x);
}
r->next=NULL;
return h;
}
求链表长度
int getLength_LinkList(LinkList h);
int getLength_LinkList(LinkList h)
{
Node *p=h;
int Length=0;
while(p->next!=NULL)
{
p=p->