数据结构复习第一天单链表的操作集合
2018-01-04 16:30
274 查看
#include <stdio.h> #include <stdlib.h> #include <malloc.h> typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next; }LNode,*LinkList; LinkList Forward_Insert() { ElemType n,cur; LinkList L; L=(LNode *)malloc(sizeof(LNode)); L->next=NULL; while(scanf("%d",&cur) != EOF) { LNode *p; p=(LinkList)malloc(sizeof(LNode)); p->data=cur; p->next=L->next; L->next=p; } return L; } LinkList Tail_Insert() { LinkList L; ElemType cur; LNode *tail; L=(LNode *)malloc(sizeof(LNode)); L->next=NULL; tail=L; while(scanf("%d",&cur) != EOF) { LNode *p; p=(LinkList)malloc(sizeof(LNode)); p->data=cur; tail->next=p; tail=p; } tail->next=NULL; return L; } void Print_List(LinkList L) { LinkList p; p=L; while(p->next) { printf("%d ",p->next->data); p=p->next; } printf("\n"); } LNode *Find_Position(LinkList L,int i) { int key=0; LNode *cur=L; while(cur!=NULL&&key<i) { cur=cur->next; key++; } return cur; } void Delete_LNode(LinkList L,int i) { LNode *front,*cur; front=Find_Position(L,i-1); cur=Find_Position(L,i); front->next=cur->next; free(cur); } void Delete_LNode_By_Value(LinkList L,int i) { LNode *cur,*front; front=L; cur=L->next; while(cur->data!=i) { front=cur; cur=cur->next; } front->next=cur->next; free(cur); } void Insert_Tail(LinkList L,int data,int pos) { LNode *temp; LNode *new_LNode=(LNode *)malloc(sizeof(LNode)); temp=Find_Position(L,pos); new_LNode->data=data; new_LNode->next=temp->next; temp->next=new_LNode; } LNode *Reverse_List_Loop(LNode *head) { LNode *next; LNode *prev=NULL; while(head!=NULL) { next=head->next; head->next=prev; prev=head; head=next; } return prev; } LNode *Reverse_List_Recurrence(LNode *head) { LNode * new_Head; if((head==NULL)||(head->next==NULL)) { return head; } new_Head=Reverse_List_Recurrence(head->next); head->next->next=head; head->next=NULL; return new_Head; } int main() { LinkList L; LNode *cur; L=Tail_Insert(); Print_List(L); //Delete_LNode(L,2); //Delete_LNode_By_Value(L,2); //Insert_Tail(L,0,3); L->next=Reverse_List_Recurrence(L->next); Print_List(L); return 0; }
关于单链表的逆序也是看了这个大佬的博客
大家可以去看看
http://blog.csdn.net/autumn20080101/article/details/7607148
相关文章推荐
- 数据结构复习之单链表:基本操作及逆序打印、逆转、合并等
- 数据结构复习--java实现单链表基本操作
- 《数据结构》 单链表常用操作代码集合
- 数据结构——单链表(链表操作算法集合)
- 笔试常考的数据结构-单链表操作实现
- python基础 第一天 (列表操作、字典操作,集合操作,文件操作)
- C数据结构 单链表操作
- 一步一步复习数据结构和算法基础-二叉树基本操作
- 数据结构链表的操作集合(建立,遍历,插入,删除,排序,长度,空判断等)
- 笔试面试常考数据结构-单链表常用操作编程实现
- 数据结构学习(二)——单链表的操作之头插法和尾插法创建链表
- 数据结构_完成单链表的后续操作实现
- 复习数据结构—单链表
- 数据结构复习笔记(数据类型及单链表实现)
- 算法数据结构 单链表的实现+操作 以及和顺序表的对比
- 数据结构复习——二叉树的几个基本操作
- 【C++/数据结构】单链表的基本操作
- 数据结构学习一(单链表的操作)
- 《数据结构》 循环链表和双向链表常用操作代码集合
- 数据结构复习-线性表的定义和基本操作