C实现单链表
来源:互联网 发布:韩国申遗 知乎 编辑:程序博客网 时间:2024/04/29 14:41
typedef int DataType;typedef struct ListNode{DataType data;struct ListNode* next;}ListNode;//初始化链表void InitList(ListNode** pphead){*pphead = NULL;}//创建节点ListNode* BuyNode(DataType x){ListNode* tmp = (ListNode*)malloc(sizeof(ListNode));assert(tmp);tmp->data = x;tmp->next = NULL;return tmp;}//尾插void PushBack(ListNode** phead,DataType x){if(NULL == *phead){*phead = BuyNode(x);}else{ListNode* tial = *phead;while(tial->next != NULL){tial = tial->next;}tial->next = BuyNode(x);}}//打印void Print(ListNode* phead){ListNode* tmp = phead;while(tmp != NULL){printf("%d->",tmp->data);tmp = tmp->next;}printf("NULL");printf("\n");}//前插void PushFront(ListNode** phead,DataType x){if(*phead == NULL){*phead = BuyNode(x);}else{ListNode* tmp = BuyNode(x);tmp ->next = *phead;*phead = tmp;}}//尾删void PopBack(ListNode** phead){if(*phead == NULL){printf("kd");return;}else{ListNode* tmp = *phead;(*phead) = (*phead)->next;free(tmp);} }//找节点ListNode* Find(ListNode* phead,DataType x){if(NULL == phead){printf("KONG");return;}else{ListNode* cur = phead;while(cur){if(cur->data = x){return cur;}cur = cur->next;}return cur;}}//插入void Insert(ListNode* pos,DataType x){ListNode* tmp = BuyNode(x);tmp->next = pos->next;pos->next = tmp;}//翻转单链表ListNode* Reverse(ListNode* phead){ListNode* newhead = NULL;ListNode* tmp = phead;while(tmp){ListNode* cur = tmp;tmp = tmp->next;cur->next = newhead;newhead = cur;/*ListNode* cur = tmp->next;tmp->next = newhead;newhead = tmp;tmp = tmp->next;*/}return newhead;}//从尾到头打印单链表void printListFromTailToHead(ListNode* head) { if(head == NULL) { return; } ListNode *newhead = NULL; ListNode *cur = head; while(cur) { ListNode *tmp = cur; cur = cur->next; tmp->next = newhead; newhead = tmp; } ListNode *p = newhead; while(p) { cout<<p->val<<endl; p = p->next; } }
1 0
- 单链表(C#)实现
- 用C实现单链表
- C实现单链表
- C语言实现单链表
- 数据结构---单链表c实现
- C语言实现单链表
- 单链表的C实现
- C语言单链表实现
- 单链表实现(C++)
- C语言实现单链表
- 单链表C语言实现
- c语言单链表实现
- 单链表反转 c实现
- 单链表之C实现
- 单链表-C实现-初级
- 单链表 C语言实现
- 单链表实现-c
- 【C++】单链表的实现
- 浅析Linux Device Tree - 基础部分
- x509 certificate has expired or is not yet valid
- Java内存模型FAQ(七)同步会干些什么呢
- JS函数表达式
- 用 IntelliJ IDEA 新建 JAVA 工程
- C实现单链表
- opencv 提升树的使用及注意事项
- C++作业2
- 指南针为什么不叫指北针
- 关于重写的listview adapter中,在getView()方法中,打印语句时,相同的position打印了多次,重复调用问题
- jvm的堆,栈,方法区
- Excel文档转化为DataTable
- java中map的取值
- android studio 断开与SVN连接的 一种方法