摘要:题目:给出二叉树的先序序列,构造对应的二叉链表,并写出遍历二叉数的代码解答:#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
阅读全文
摘要:题目:将两个已经排序的单向链表合并为一个链表解答:// 归并版本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; ...
阅读全文
摘要:题目:输入一个链表,输出这个链表中倒数第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 *
阅读全文
摘要:题目: 输入一个链表的头结点,反转该链表并输出反转后链表的头结点解法:循环版本:// 循环版本逆转链表LISTNODEPTR reverseList1(LISTNODEPTR * head) { // LISTNODEPTR frontptr = *head, backptr = *head; LISTNODEPTR frontptr, backptr; frontptr = backptr = *head; if (*head == NULL) { return NULL; } if (*head->next = NULL) { ...
阅读全文