📄 shapiro.c
字号:
/* * $Log: shapiro.c,v $ * Revision 1.1 2000/05/03 14:30:04 bjc97r * Initial revision * * */char *_shapiro_id = "$Id: shapiro.c,v 1.1 2000/05/03 14:30:04 bjc97r Exp $";#include <stdlib.h>#include <string.h>void shapiro( char *s, char *c, int n ) /* * s should point to a valid char array of 2^n * c should point to a valid char array of 2^n * The generated pair of Shapiro-Rudin sequences will be * stored in s and c. * n is the order of the sequence. The actual length * will be 2^n. */{ s[0] = 1; s[1] = 1; c[0] = 1; c[1] = -1; if ( n < 2 ) return; { int i, j, N0, N; N0 = 1; N = 2; for ( i=1; i < n; i++ ) { N0 <<= 1; N <<= 1; memcpy( s+N0, c, N0 ); memcpy( c, s, N0); for ( j=N0; j < N; j++ ) c[j] = -s[j]; } }}static void invcpy( char *d, char *s, int size ){ int i; for( i=0; i < size; i++ ) { d[i] = -s[i]; }}void sivaswamy4( char **S, int n ) /* * S[0], S[1], S[2], S[3] point to a valid char array of 2^n * n is the order of the sequence. The actual length * will be 2^n */{ char *s, *c; int N; N = 1 << (n-1); s = (char*) malloc( N * sizeof(char) ); c = (char*) malloc( N * sizeof(char) ); shapiro( s, c, n-1 ); memcpy( S[0], s, N ); memcpy( S[0]+N, s, N ); memcpy( S[1], s, N ); invcpy( S[1]+N, s, N ); memcpy( S[2], c, N ); memcpy( S[2]+N, c, N ); memcpy( S[3], c, N ); invcpy( S[3]+N, c, N ); free(s); free(c);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -