
대규모 SW 시스템을 어떻게 개발하고 관리할지

int i, *pi;
float f, *pf;
// 메모리를 따로 할당해줘야함
pi = (int *) malloc(sizeof(int));
pf = (float *) malloc(sizeof(float));
*pi = 1024;
*pf= 3.14;
printf(“an integer = %d, a float = %f\n”, *pi, *pf);
free(pi);
free(pf);
-답은,,, 미공개 ^_^
// Selection Sort Suedo code
for (i=0;i<n;i++) {
Examine list[i] to list[n-1] and suppose that
the smallest integer is at list[min];
Interchange list[i] and list[min];
}
// swap function
void swap(int *x, int *y) {
int temp *x;
*x = *y;
*y = temp;
}
#define SWAP(x,y,t) ((t)=(x),(x)=(y),(y)=(t))
#include <stdio.h>
#include <math.h>
#define MAX_SIZE 101
#define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t))
// Selection Sort
void sort(int [], int);
void main(void)
{
int i, n;
int list[MAX_SIZE];
printf(“Enter the number of numbers to generate: ”);
scanf(“%d”, &n);
if(n<1 || n> MAX_SIZE) {
fprintf(stderr, “Improper value of n\n”);
exit(EXIT_FAILURE);
}
for (i=0; i<n; i++) {
/* randomly generate numbers*/
list[i] = rand() % 1000;
printf(“%d”, list[i]);
}
sort(list, n);
printf(“\n Sorted array:\n”);
for(i=0; i<n; i++) /*print out sorted numbers */
printf(“%d”, list[i]);
printf(“\n”);
}
void sort(int list[], int n)
{
int i, j, min, temp;
for(i = 0; i < n-1; i++) {
min = i;
for (j = i + 1; j < n; j++)
if(list[j] < list[min])
min = j;
SWAP(list[i], list[min], temp);
}
}
while (there are more integers to check) {
middle = (left + right) / 2;
if(searchnum < list[middle])
right = middle-1;
else if (searchnum == list[middle])
return middle;
else
left = middle + 1;
}
int compare(int x, int y)
{
/* compare x and y, return -1 for less than,
0 for equal, 1 for greater */
if (x<y)
return -1;
else if (x == y)
return 0;
else
return 1;
}
#define COMPARE(x,y) (((x)<(y))?-1:((x)==(y))?0:1) // 삼항연산자
int binsearch(int list[], int searchnum, int left, int right)
{
/* search list [0] <= list[1] <= … <= list[n-1] for searchnum.
Return its position if found. otherwise return -1 */
int middle;
while (left <= right) {
middle = (left + right) / 2;
switch (COMPARE(list[middle], searchnum)) {
case -1: left = middle + 1
break;
case 0 : return middle;
case 1 : right = middle -1;
}
}
return -1;
}
int binsearch(int list[], int searchnum, int left, int right)
{
/* search list [0] <= list[1] <= … <= list[n-1] for searchnum.
Return its position if found. Otherwise return -1 */
int middle;
if (left <=right) {
middle = (left + right) / 2;
switch (COMPARE(list[middle], searchnum)) {
case -1:
return binsearch(list, searchnum, middle+1, right);
case 0 :
return middle;
case 1 :
return binsearch(list, searchnum,left, middle-1);
}
}
return -1;
}
-답은,,, 미공개 ^_^
이제는 메모리가 충분해져서 Space 보다는 Time에 비중을 두고 개발하는 추세
| Method 1 | Method 2 | |
|---|---|---|
| Start timing | start = clock(); | start = time(NULL); |
| Stop timing | stop = clock(); | stop = time(NULL); |
| Type returned | clock_t | time_t |
| Results in second | Duration = ((double)(stop-start))/CLOCKS_PER_SEC | duration = (double) difftime(stop,start); |
float sum(float list[], int n)
{
float tempsum = 0;
count++; /*for assignment */
int i;
for(i=0; i<n; i++) {
count++; /*for the for loop */
tempsum += list[i];
count++; /*for assignment */
}
count++; /* last execution of for */
count++; /* for return */
return tempsum;
}



-답은,,, 미공개 ^_^