[ create a new paste ] login | about

Link: http://codepad.org/6CjGO1SI    [ raw code | output | fork | 1 comment ]

ototoyume - C, pasted on Feb 6:
//・最も左側の要素を軸とする.
//・軸と等しい値は右側に移動する.
//・関数void quick(int a[], int left, int right)の中で,leftがright以上になったときに,再帰処理を終了する.





#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void quick(int *, int, int);

#define N 10

int  main(void){
	int a[N] = {0};
	int k = 0;

	for (k = 0; k < N ; k++) {
		printf("Input a number: ");
		scanf("%d", &a[k]);
	}

	printf("before: ");
	for (k = 0; k < N; k++) {
		printf("%4d", a[k]);
	}
	printf("\n");

	quick(a, 0, N - 1);
	
	printf("after:  ");
	for (k = 0; k < N; k++) {
		printf("%4d", a[k]);
	}
	printf("\n");
}

void check(int a[], int left, int right, int p, int center) {
	int i = 0;
	printf("(%d, %d) pivot: %d, center: %d\n", left, right, p, center);
	for (i = 0; i < N; i++) {
		printf("%4d", a[i]);
	}
	printf("\n");
}

int pivot(int a[], int left, int right) {
	return left;
}

int swap(int *x, int *y) {
	int t = *x;
	*x = *y;
	*y = t;
}

int partition(int a[], int left, int right, int p) {

// 
(* ここに解答を書き加える *)
 

}

void quick(int a[], int left, int right) {

// 
(* ここに解答を書き加える *)
	

	check(a, left, right, p, center);
	quick(a, left, center - 1);
	quick(a, center, right);
}


Output:
In function 'partition':
Line 63: error: stray '\343' in program
Line 63: error: stray '\201' in program
Line 63: error: stray '\223' in program
Line 63: error: stray '\343' in program
Line 63: error: stray '\201' in program
Line 63: error: stray '\223' in program
Line 63: error: stray '\343' in program
Line 63: error: stray '\201' in program
Line 63: error: stray '\253' in program
Line 63: error: stray '\350' in program
Line 63: error: stray '\247' in program
Line 63: error: stray '\243' in program
Line 63: error: stray '\347' in program
Line 63: error: stray '\255' in program
Line 63: error: stray '\224' in program
Line 63: error: stray '\343' in program
Line 63: error: stray '\202' in program
Line 63: error: stray '\222' in program
Line 63: error: stray '\346' in program
Line 63: error: stray '\233' in program
Line 63: error: stray '\270' in program
Line 63: error: stray '\343' in program
Line 63: error: stray '\201' in program
Line 63: error: stray '\215' in program
Line 63: error: stray '\345' in program
Line 63: error: stray '\212' in program
Line 63: error: stray '\240' in program
Line 63: error: stray '\343' in program
Line 63: error: stray '\201' in program
Line 63: error: stray '\210' in program
Line 63: error: stray '\343' in program
Line 63: error: stray '\202' in program
Line 63: error: stray '\213' in program
Line 63: error: expected expression before ')' token
In function 'quick':
Line 71: error: stray '\343' in program
Line 71: error: stray '\201' in program
Line 71: error: stray '\223' in program
Line 71: error: stray '\343' in program
Line 71: error: stray '\201' in program
Line 71: error: stray '\223' in program
Line 71: error: stray '\343' in program
Line 71: error: stray '\201' in program
Line 71: error: stray '\253' in program
Line 71: error: stray '\350' in program
Line 71: error: stray '\247' in program
Line 71: error: stray '\243' in program
Line 71: error: stray '\347' in program
Line 71: error: stray '\255' in program
Line 71: error: stray '\224' in program
Line 71: error: stray '\343' in program
Line 71: error: stray '\202' in program
Line 71: error: stray '\222' in program
Line 71: error: stray '\346' in program
Line 71: error: stray '\233' in program
Line 71: error: stray '\270' in program
Line 71: error: stray '\343' in program
Line 71: error: stray '\201' in program
Line 71: error: stray '\215' in program
Line 71: error: stray '\345' in program
Line 71: error: stray '\212' in program
Line 71: error: stray '\240' in program
Line 71: error: stray '\343' in program
Line 71: error: stray '\201' in program
Line 71: error: stray '\210' in program
Line 71: error: stray '\343' in program
Line 71: error: stray '\202' in program
Line 71: error: stray '\213' in program
Line 71: error: expected expression before ')' token
Line 75: error: 'center' undeclared (first use in this function)
Line 75: error: (Each undeclared identifier is reported only once
Line 75: error: for each function it appears in.)


Create a new paste based on this one


Comments:
posted by ototoyume on Feb 6
//・最も左側の要素を軸とする.
//・軸と等しい値は右側に移動する.
//・関数void quick(int a[], int left, int right)の中で,leftがright以上になったときに,再帰処理を終了する.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void quick(int *, int, int);

#define N 10

int main(void){
int a[N] = {0};
int k = 0;

for (k = 0; k < N ; k++) {
printf("Input a number: ");
scanf("%d", &a[k]);
}

printf("before: ");
for (k = 0; k < N; k++) {
printf("%4d", a[k]);
}
printf("\n");

quick(a, 0, N - 1);

printf("after: ");
for (k = 0; k < N; k++) {
printf("%4d", a[k]);
}
printf("\n");
}

void check(int a[], int left, int right, int p, int center) {
int i = 0;
printf("(%d, %d) pivot: %d, center: %d\n", left, right, p, center);
for (i = 0; i < N; i++) {
printf("%4d", a[i]);
}
printf("\n");
}

int pivot(int a[], int left, int right) {
return left;
}

int swap(int *x, int *y) {
int t = *x;
*x = *y;
*y = t;
}

int partition(int a[], int left, int right, int p) {

//
(* ここに解答を書き加える *)

}

void quick(int a[], int left, int right) {

//
(* ここに解答を書き加える *)

check(a, left, right, p, center);
quick(a, left, center - 1);
quick(a, center, right);
}


reply