随笔分类 -  c

用c写算法4[二叉数的构造以及遍历]
摘要:题目:给出二叉树的先序序列,构造对应的二叉链表,并写出遍历二叉数的代码解答:#include <stdio.h>#include <stdlib.h>#include <string.h>/*Tree.c: implements the datastructure of string in P127*/#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2typedef int Status;typedef int TEl 阅读全文

posted @ 2013-03-28 09:39 jiyiyouxin 阅读(265) 评论(0) 推荐(0)

用c写算法3[合并两个排序的链表]
摘要:题目:将两个已经排序的单向链表合并为一个链表解答:// 归并版本ListNode * mergeList1(ListNode* pHead1, ListNode* pHead2) { if (pHead1 == NULL) return pHead2; else if (pHead2 == NULL) return pHead1; ListNode* pMergeHead = NULL; if (pHead1->m_nValue < pHead2->m_nValue) { pMergeHead = pHead1; ... 阅读全文

posted @ 2013-03-28 08:06 jiyiyouxin 阅读(256) 评论(0) 推荐(0)

用c写算法2[链表中倒数第k个结点]
摘要:题目:输入一个链表,输出这个链表中倒数第k个结点解法:#include <stdio.h>#include <stdlib.h>#include <string.h>struct ListNode{ int m_nValue; struct ListNode * m_pNext;};typedef struct ListNode ListNode;typedef ListNode * LISTNODEPTR;ListNode * FindKthToTail(ListNode *, unsigned int);void insert(LISTNODEPTR * 阅读全文

posted @ 2013-03-27 16:17 jiyiyouxin 阅读(162) 评论(0) 推荐(0)

用c写算法1[逆置链表]
摘要:题目: 输入一个链表的头结点,反转该链表并输出反转后链表的头结点解法:循环版本:// 循环版本逆转链表LISTNODEPTR reverseList1(LISTNODEPTR * head) { // LISTNODEPTR frontptr = *head, backptr = *head; LISTNODEPTR frontptr, backptr; frontptr = backptr = *head; if (*head == NULL) { return NULL; } if (*head->next = NULL) { ... 阅读全文

posted @ 2013-03-26 17:11 jiyiyouxin 阅读(206) 评论(0) 推荐(0)