Skip to content

Instantly share code, notes, and snippets.

View paranoidxc's full-sized avatar
💭
换工作中 (FUCKING THE ALL WORLD)

paranoidxc

💭
换工作中 (FUCKING THE ALL WORLD)
  • 五四北 福州 福建
View GitHub Profile
@paranoidxc
paranoidxc / malloc_array
Created August 8, 2014 07:17
动态分配数组
#include "HEDE_FILE"
int main() {
int *array, i, n;
scanf("%d", &n);
array = (int *)Malloc( n * sizeof(int) );
for( i = 0; i < n; i ++ ) {
scanf("%d", &array[i]);
}
exit(0);
/*
快速排序算法之所以得到广泛的应用是因为它在很多情况下都能运行的很好,其他方法可能更合适解决某些特定的情况,而快速排序算法可以比其他方法处理更多的排序问题,而且它通常会比其他可选择的方案更快.
*/
/*
基本快速排序算法
*/
int partition(Item a[], int l, int r);
void quicksort(Item a[], int l, int r)
@paranoidxc
paranoidxc / 数组排序的例子
Last active August 29, 2015 14:01
排序函数是一种插入排序法. 假设待排序的元素的类型为Item, 定义在其上的操作符有 less(比较两个关键字), exch(交换两个元素) 和 compexch(比较两个元素)
#include <stdio.h>
#include <stdlib.h>
typedef int Item;
#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define exch(A, B) { Item t = A; A = B; B = t; }
//#define exch(A, B) { A = A^B; B = B ^ A; A = A ^ B; }
#define compexch(A, B) if (less(B, A)) exch(A, B)
/*
Item max(Item a[], int l, int r)
{
Item u, v; int m = (l+r)/2;
if (l == r) return a[l];
u = max(a, l, m);
v = max(a, m+1, r);
if (u > v) return u; else return v;
}
int gcd(int m, int n) {
if ( n == 0 ) return m;
return gcd(n, m % n);
}
#include <stdio.h>
int main () {
printf("%d\n", gcd( 12, 8 ) );
system("pause");
}
/*
(x+1)的N次方的多项式
*/
#include <stdio.h>
#include <stdlib.h>
#include "POLY.h"
main(int argc, char *argv[])
{ int N = atoi(argv[1]); float p = atof(argv[2]);
Poly t, x; int i, j;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Nmax 10
#define Mmax 20
char buf[Mmax];
int M = 0;
int compare(void *i, void *j) {
#include <stdio.h>
#define N 20
main( int argc, char *argv[] ) {
int i, j, t;
char a[N], *p = argv[1];
for ( i = 0; i < N-1; a[i] = t, i++ ) {
if ( (t=getchar()) == EOF ) {
break;
/*
链表排序
*/
#include <stdlib.h>
typedef struct node* link;
struct node
{
int item;
link next;
link reverse( link x ) {
link t, y = x, r = NULL;
while ( y != NULL ) {
t = y->next;
y->next = r;
r = y;
y = t;
}
}