自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(45)
  • 收藏
  • 关注

原创 数据结构题典022:栈的应用——行编辑程序(C语言版)

编写程序实现从终端接收用户输入的数据,并存入用户数据区。输入#表示上一字符无效,输入@表示当前输入行整行无效。/* * line editor by using stack. * * fduan, Dec. 31, 2011. */void line_editor(){ using std::stack; stack ss; std::string li

2011-12-31 04:20:23 3642 1

原创 数据结构题典021:栈的应用——括号匹配的检验(C++)

题目:假设表达式中允许出现圆括号和方括号,其嵌套顺序随意,设计算法检验给定表达式中的括号是否匹配。/* * Brackets matching algorithm by utilizing stack. * * fduan, Dec. 31, 2011. */bool is_pair( char c1, char c2 ){ return ( c1 == '(' && c2

2011-12-31 03:16:18 2026

原创 数据结构题典020:栈的应用——数制转换(ANSI C)

题目:将十进制数 src 转换为 k 进制数。原理:N = ( N div k ) x k + N mod k,其中div为整除,mod为取余。void num_sys_convert( int src, int k ){ link_stack ls; init_stack_link( &ls ); while( src != 0 ) { push_link( &ls,

2011-12-30 15:02:58 669

原创 链式栈的实现(ANSI C)

1、链式栈ADT的定义#ifndef _link_stack_h#define _link_stack_htypedef int elem_type;struct stack_node;typedef struct stack_node stack_node;typedef stack_node * snode_ptr;typedef stack_node * link_sta

2011-12-30 14:33:50 464

原创 顺序栈的实现(ANSI C)

1、顺序栈ADT定义#ifndef _seq_stack_h#define _seq_stack_h#define STACK_INIT_SIZE 100#define STACK_INCR_SIZE 10typedef struct seq_stack{ int * base; int * top; int size;}seq_stack;void init_sta

2011-12-30 14:15:24 510

原创 数据结构题典018:三个有序单链表求交(ANSI C)

题目:设有三个带头结点的元素按非递减有序排列的单链表A, B, C,对A进行如下操作,使A中仅含有三个表中的交,且没有值相同的结点,并释放无用结点。限定时间复杂度为O( m + n + p ),其中m, n, p分别为三个表的长度。/* * Intersection of three ordered linked lists. * * fduan, Dec. 29, 2011.

2011-12-29 23:24:36 1010

原创 一些SSM(Statistical Shape Model)资源

http://www.isbe.man.ac.uk/research/Flexible_Models/pdms.html// 待补充……

2011-12-29 23:03:53 1906

原创 数据结构题典017:从无序数据建立有序顺序表(ANSI C)

题目:从无序的输入数据中建立一个递增有序的顺序表。int order_insert_array( int x[], int e, int n, int m ){ int len = m, pos, i; if( m == 0 ) x[len++] = e; else { i = 0; while( i < m && x[i] < e ) ++i; pos = (

2011-12-29 22:59:00 1898

原创 数据结构题典016:按递增次序输出单链表所有元素(ANSI C)

题目:按递增次序输出单链表所有元素,并释放结点的存储空间。要求不使用数组做辅助空间。#include void min_elem( link_list * lst, node_ptr * min_prev, node_ptr * min_ptr ){ node_ptr p = (*lst)->next, prev = NULL; elem_type min_v = INT_MAX;

2011-12-29 02:40:09 3005

原创 数据结构题典014:单链表的子序列检测(ANSI C)

题目:设有两个整数序列 A = a_1, a_2, ..., a_m和 B = b_1, b_2, ..., b_n已存入两个单链表,设计算法判断序列B是否为序列A的子序列。int is_subseq_llist( link_list lst_a, link_list lst_b ){ node_ptr pa = lst_a->next, pb = lst_b->next; while(

2011-12-29 00:13:23 1344 1

原创 数据结构题典013:链表合并之二(ANSI C)

题目:设有两个元素递增的单链表(带头结点),编写算法将二者合并为按元素递减排列的链表L,要求利用原表的结点空间存放L。/* * fduan, Dec. 28, 2011. */void calc_union_v2( link_list * lst_a, link_list * lst_b ){ node_ptr pa = *lst_a, pb = *lst_b, p = NULL;

2011-12-28 23:50:35 811

原创 数据结构题典012:链表求交集之二(ANSI C)

问题:已知两个按元素递增排列的链表,求二者交集,要求将结果放入第一个链表中。/* * Intersection of two ordered linked lists. * * fduan, Dec. 28, 2011. */void intersect_v2( link_list * lst_a, link_list lst_b ){ node_ptr pa = *lst_a

2011-12-28 23:24:09 990

原创 数据结构题典011:有序单链表的并集(ANSI C)

题目:与009类似,但这次是求并集。分析:与有序顺序表归并思路类似,只是注意要处理两个顺序表当前指针指向的元素相同的情形(此时只为并集中增加一项)。/* * Union set of two linked lists which have non-descending order. * * fduan, Dec. 28, 2011. */void calc_union( lin

2011-12-28 22:24:52 1812

原创 数据结构题典010:有序单链表的交集(ANSI C)

题目:设有两个非递减有序的单链表,编写算法求二者的交集(以链表形式存放),要求交集中元素保持递增有序。分析:此题关键是要跳过相邻的重复元素。/* * Intersection of two non-descending linked lists. * * fduan, Dec. 28, 2011. */void intersection( link_list lst_a, l

2011-12-28 22:08:45 1928

原创 数据结构题典009:递归实现单链表逆序数出(ANSI C)

设所考虑单链表含头结点,写出逆序输出表中元素的递归算法。void inv_trav_recur( link_list p ){ if( p != NULL ) { inv_trav_recur( p->next ); printf( "%d ", p->data ); }}void inverse_traverse_llist( link_list lst ){ i

2011-12-28 08:56:57 1009

原创 数据结构题典008:顺序表的合并(ANSI C)

题意:设有顺序表La和Lb,二者中元素均为非递减有序,空间足够大。设计算法将Lb中的元素合并到La中,使新的La元素仍非递减有序。分析:此题与将两个有序顺序表合并到第三个顺序表中的思路类似,只是为了减少移动次数,比较的次序从两线性表的尾部开始,这样每个元素最多只移动一次。/* * merging of two ordered sequences * * fduan, Dec. 27,

2011-12-28 01:25:43 875

原创 数据结构题典007:顺序表中元素块的位置交换(ANSI C)

假设有顺序表 L.elem[] = { a_1, a_2, ..., a_m, | b_1, b_2, ..., b_n },设计算法将L的两部分元素互换,使得 L.elem[] = { b_1, b_2, ..., b_n, |a_1, a_2, ..., a_m }思路一:循环移位,数组整体循环右移n个元素void circ_right_shift( int c[], int len,

2011-12-26 00:20:36 2234

原创 数据结构题典006:有序表中冗余元素的删除(ANSI C)

1、顺序表,假设元素已按升序排序/* * remove redundant elements from ordered sequence */int remove_redundant_elem( int c[], int n ){ int i = 0, j = 1; while( j < n ) { if( c[i] != c[j] ) c[++i]

2011-12-25 19:24:57 778

原创 数据结构题典005:单链表的复制(ANSI C)

数据结构题典005:单链表的复制(ANSI C)void clone_node( node_ptr src, node_ptr * dst ){ if( src != NULL ) { *dst = ( node_ptr )malloc( sizeof( node ) ); (*dst)->data = src->data; } else *dst = NULL;}

2011-12-25 10:48:23 766

原创 数据结构题典004:对单链表元素插入排序(ANSI C)

带头结点的单链表void insert_sort_llist( link_list * lst ){ node_ptr h = *lst, p = h->next, r = NULL, q = NULL; h->next = NULL; while( p != NULL ) { q = p->next; r = h; while( r->next != NULL && r

2011-12-25 10:38:00 755

原创 数据结构题典003:线性表的就地逆置/翻转(ANSI C)

1、顺序表a) 通过数组下标访问元素/* * 通过数组下标访问 */void reverse_sqlist( int c[], int n ){ int i = 0, j = n - 1; int t; for( ; i < j; ++i, --j ) { t = c[i]; c[i] = c[j]; c[j] = t; }}b) 通过指针访问元素/

2011-12-25 02:29:54 1076

原创 数据结构题典002:删除单链表中最大元素所在结点(ANSI C)

分析:此题关键在于找到最大元素所在的前驱结点。status_code remove_max_elem_llist( link_list * lst, elem_type * e ){ status_code res = Success; node_ptr h = *lst, p = h, pre_max = p; int max_v = -1000; while( p->next

2011-12-25 01:24:13 3266

原创 数据结构题典001:有序线性表的归并(ANSI C)

1、有序顺序表的归并排序,假设a[0] void merge_list( int a[], int m, int b[], int n, int ** c ){ int i = 0, j = 0; int *pa = a, *pb = b, *pc = NULL, *qa = a + m - 1, *qb = b + n - 1; if( *c != NULL )

2011-12-24 22:14:21 752

原创 用单链表实现多项式运算(ANSI C)

1、多项式结构定义polynomial.h#ifndef _polynomial_h#define _polynomial_hstruct poly_term{ int expn; int coef;};typedef struct poly_term poly_term;typedef poly_term * poly_term_ptr;struct poly_n

2011-12-23 02:48:01 747

原创 双循环链表的实现(ANSI C)

1、double_link_list.h#ifndef _double_link_list_h#define _double_link_list_h#include "common.h"typedef int elem_type;struct node;typedef struct node node;typedef node * node_ptr;typedef no

2011-12-21 00:58:58 451

原创 单循环链表结构的实现(ANSI C)

1、首先定义公共头文件common.h,其中包含了枚举类型status_code的定义,目的是将其作为循环链表结构操作的返回类型。#ifndef _common_h#define _common_henum status_code { Success, Fail, MemoryOut, NotPresent, RangeError };typedef enum status_co

2011-12-20 04:03:35 712

原创 K&R C Exercise 3-1 Solution

/* * Exercise 3-1 Write the binary search algorithm with only * one test inside the loop. * * Written by fduan on Dec. 15, 2011. */#include /* binary search: v[0] <= v[1] <= ... <= v[n-1] */

2011-12-15 03:00:01 996

原创 K&R C Exercise 2-9 Solution

/* * Exercise 2-9 In a two's complement number system, * x & ( x - 1 ) deletes the rightmost 1-bit in x. * Use this to write a fast version of bitcount. * * Written by fduan on Dec. 14, 2011.

2011-12-15 02:43:28 645

原创 K&R C Exercise 2-8 Solution

/* * Exercise 2-8 Write a function rightrot(x, n) that * returns the value of the integer x rotated to the * right by n bit positions. * * Written by fduan on Dec, 14, 2011. */#include /* th

2011-12-15 02:33:15 1091

原创 K&R C Exercise 2-7 Solution

/* * Exercise 2-7 Write a function invert(x, p, n) that returns * x with the n bits that begins at position p inverted, leaving * the other bits unchanged. * * fduan, Dec. 14, 2011. */#include

2011-12-15 02:03:39 763

原创 K&R C Exercise 2-6 Solution

/* * Exercise 2-6 Write a function setbits( x, p, n, y ) that * returns x with the n bits that begin at position p set to * the rightmost n bits of y, leaving the other bits unchanged. * * fduan

2011-12-14 02:26:26 827

原创 判断单链表中环存在与否的判别(C++)

这是一道面试题,要求用最简洁的代码写出判别单链表中是否存在环。我是这样做的,可将单链表视作一种简化的图,在依照链表指针域遍历链表时,保留每个结点的入度,若在到达尾结点之前出现入度为2的结点,说明链表中存在环,同时终止遍历。/* * 判别单链表中是否存在环 */#include using std::map;typedef int elem_type;struct Node

2011-12-13 17:38:38 673

原创 K&R C Exercise 2-5 Solution

/* * Exercise 2-5 Write the function any( s1, s2 ), which returns * the first location in the string s1 where any character from * the string s2 occurs, or -1 if s1 contains no character from * s

2011-12-13 01:23:52 593

原创 K&R C Exercise 2-4 Solution

/* * Exercise 2-4 Write an alternate version of squeeze( s1, s2 ) * that deletes each character in s1 that matches any character * in the string s2. * * fduan, Dec. 12, 2011. */#include void

2011-12-13 00:53:30 760

原创 K&R C Exercise 2-3 Solution

/* * Exercise 2-3 Write the function htoi(s), which converts a string * of hexadecimal digits into its equivalent integer value. */#include #include #define MAX_LEN 10int is_valid_hex_alpha(

2011-12-12 11:59:46 851

原创 K&R C Exercise 1-22 Solution

/* * Exercise 1-22 Write a program to "fold" long input lines into * two or more shorter lines after the last non-blank character * that occurs before the n-th column of input. Make sure your *

2011-12-12 00:15:07 648

原创 K&R C Exercise 1-21 Solution

/* * Exercise 1-21 Write a program entab that replaces strings of blanks * by the minimum number of tabs and blanks to achieve the same spacing. * * fduan, Dec. 12, 2011 */#include #define TA

2011-12-11 21:38:42 647

原创 K&R C Exercise 1-20 Solution

/* * Exercise 1-20 Write a program detab that replaces tabs in the input * with the proper number of blanks to space to the next tab stop. Assume * a fixed set of tab stops, say every n columns. *

2011-12-11 16:42:14 1268

原创 K&R C Exercise 1-19 Solution

/* * Exercise 1-19 Write a function reverse(s) that reverses * that character string s. Use it to write a program that * reverses its input a line at a time. * * fduan, Dec. 11, 2011 */#includ

2011-12-11 01:36:01 554

原创 K&R C Exercise 1-18 Solution

/* * Exercise 1-18 Write a program to remove trailing blanks and tabs from * each line of input, and to delete the entirely blank lines. * * fduan, Dec. 11, 2011 */#include #define MAX_LEN 10

2011-12-11 01:35:21 719

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除