Skip to content

Instantly share code, notes, and snippets.

@tinylamb
tinylamb / chapter 4.c
Last active December 24, 2015 11:09
<The C Programming language>-chapter 4 Functions and Program Structure undo 8/9/10/11.keywords: 字符串匹配
/*reference http://users.powernet.co.uk/eton/kandr2/index.html*/
/*
Exercise 4-1. Write the function strindex(s,t) which returns the position of
the first occurrence of t in s, or -1 if there is none.
*/
#include <stdio.h>
#define SIZE 100
int strindex(char s[] , char p[]);//return (p in s)?index:-1
@tinylamb
tinylamb / Stack.c
Last active December 25, 2015 08:49
ADT stack
#include <stdio.h>
#include <stdlib.h>
#define ElemType int
#define MAXSIZE 100
/*...ADT stack...*/
/*数据集定义*/
typedef struct Stack{
int stacksize;
@tinylamb
tinylamb / ch5.c
Last active December 25, 2015 11:39
<The C Programming language> -chap5 Pointer and Array 15/20
/*
Exercise 5-1. As written, getint treats a + or - not followed
by a digit as a valid representation of zero.
Fix it to push such a character back on the input.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXSIZE 100
int getch();
@tinylamb
tinylamb / sort_algorithm.c
Last active December 26, 2015 00:19
Sort Algorithm
/*
quick sort v1
http://zh.wikipedia.org/wiki/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F
*/
#include<stdio.h>
void qsort(int a[],int left,int right);
int findp(int v[],int left,int right);//find pivot position
void swap(int *,int *);
int main(){
int a[]={5,4,3,1,4,5,6,8,9,0};
@tinylamb
tinylamb / ch6.c
Last active December 27, 2015 10:39
<The C Programming language> -chap6 Structures
/*Exercise 6-1. Our version of getword does not
* properly handle underscores, string constants,
* comments, or preprocessor control lines. Write a better version.
*/
#include <stdio.h>
#include <ctype.h>
#define LIMIT 20
#define STRCONSTANT 0
#define COMMENT 1
#define WORD 2
@tinylamb
tinylamb / Crawler.py
Last active December 28, 2015 18:29
抓取豆瓣日志信息的爬虫,信息包括 日志名称,URL,评论数,发布时间
#encoding:utf-8
from Tkinter import *
import urllib2
from lxml import html
import os,sys
class App:
def __init__(self,master):
self.label=Label(master,text='输入日记首页地址:')
self.label.pack(side='left',padx=5)
@tinylamb
tinylamb / random_file.c
Created November 20, 2013 13:41
<The practice of Programming>markov链.keywords: hash table
/*
#include <stdio.h>
#define FILEPATH "/Users/tinylamb/Documents/coding/santi.txt"
int main(){
FILE *fp;
fp=fopen(FILEPATH,"r");
char c;
while((c=fgetc(fp))!=EOF)
printf("%c",c);
fclose(fp);
@tinylamb
tinylamb / findk.c
Created November 24, 2013 06:36
find k-th small number
/*input :A[n]
* output:k-th large number
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define LEN(a) (int)(sizeof(a)/sizeof(a[0]))
#define SWAP(a,b) do{int temp;temp=a;a=b;b=temp;}while(0)
int searchk(int a[],int left,int right,int k);
void print(int a[],int start,int end);
@tinylamb
tinylamb / calculator.c
Last active December 29, 2015 10:39
基于中缀表达式的计算器.keywords: inorder tree变后缀; enum 类型与宏定义
/*
* =========================================================
* Filename: calculator.c
* Description: deal with expression like this (4+2)*5-6/(2+1)
* number , + - * / , ()
* 1.convert in-order to post-order
* 2.you know how to compute post-order expr
*
* =========================================================
*/
@tinylamb
tinylamb / maze.c
Last active December 30, 2015 02:29
backtracking to find a path in maze
/*
* =========================================================
* Filename: maze.c
* Description: backtracking to find a path in maze
* refer: http://blog.csdn.net/synapse7/article/details/14411365
* =========================================================
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>