用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 阅读(150) 评论(0) 推荐(0)

用python写算法7[调整数组顺序]

摘要: 题目:解法:维护两个索引,如果第一个指向那个的数字是偶数,第二个指向的数字是奇数,就交换这两个数字#!/usr/bin/python#coding=gbk'''Created on 2013-03-25@author: songjian'''def adjust_seq(test_arr): begin_index = 0 end_index = len(test_arr) - 1 while begin_index < end_index: if test_arr[begin_index] % 2 == 0: while end_inde 阅读全文
posted @ 2013-03-27 15:11 jiyiyouxin 阅读(390) 评论(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 阅读(197) 评论(0) 推荐(0)