/*
#include <stdio.h>
#define MAX_ELEMENT 100
typedef struct {
int heap[MAX_ELEMENT], heap_size;
}Heap;
Heap *createHeap()
{
Heap *h=(Heap*)malloc(sizeof(Heap));
h->heap_size=0;
return h;
}
void insertHeap(Heap *h, int item)
{
int i;
h->heap_size=h->heap+1;
i=h->heap_size;
while((i!=1)&&(item>h->heap[i/2])) {
h->heap[i]=h->heap[i/2];
i/=2;
}
h->heap[i]=item;
}
int deleteHeap(Heap *h)
{
int parent, child, item, tmp;
item=h->heap[1];
tmp=h->heap[h->heap_size];
h->heap_size=h->heap_size-1;
parent=1;
child=2;
while(child<=h->heap_size) {
if((child<h->heap_size)&&(h->heap[child])<h->heap[child+1])
child++;
if(tmp>=h->heap[child]) break;
else {
h->heap[parent]=h->heap[child];
parent=child;
child=child*2;
}
}
h->heap[parent]=tmp;
return item;
}
void printHeap(Heap *h)
{
int i;
printf("Heap : ");
for(i=1;i<=h->heap_size;i++) {
printf("[%d] ", h->heap[i]);
}
}
void main()
{
int i, n, item;
Heap *heap=createHeap();
insertHeap(heap, 10);
insertHeap(heap, 45);
insertHeap(heap, 19);
insertHeap(heap, 11);
insertHeap(heap, 96);
printHeap(heap);
n=heap->heap_size;
for(i=1;i<=n;i++) {
item=deleteHeap(heap);
printf("\n delete : [%d] ", item);
}
getchar();
}
*/
/*
#include <stdio.h>
#define MAX_VERTEX 30
typedef struct {
int n, adjMatrix[MAX_VERTEX][MAX_VERTEX];
} graphType;
void createGraph(graphType *g)
{
int i, j;
g->n=0;
for(i=0;i<MAX_VERTEX;i++) {
for(j=0;j<MAX_VERTEX;j++) {
g->adjMatrix[i][j]=0;
}
}
}
void insertVertex(graphType* g, int v)
{
if(((g->n)+1)>MAX_VERTEX) {
printf("그래프 정점의 개수를 초과하였습니다! ");
return ;
}
g->n++;
}
void insertEdge(graphType* g, int u, int v)
{
if(u>=g->n||v>=g->n) {
printf("그래프에 없는 정점입니다!");
return ;
}
g->adjMatrix[u][v]=1;
}
void printf_adjMatrix(graphType* g)
{
int i, j;
for(i=0;i<g->n;i++) {
printf("\n\t\t");
for(j=0;j<g->n;j++) {
printf("%2d", g->adjMatrix[i][j]);
}
}
}
void main()
{
int i;
graphType *G1, *G2, *G3, *G4;
G1=(graphType*)malloc(sizeof(graphType));
G2=(graphType*)malloc(sizeof(graphType));
G3=(graphType*)malloc(sizeof(graphType));
G4=(graphType*)malloc(sizeof(graphType));
createGraph(G1);
createGraph(G2);
createGraph(G3);
createGraph(G4);
for(i=0;i<4;i++) {
insertVertex(G1, i);
}
insertEdge(G1, 0, 1);
insertEdge(G1, 0, 3);
insertEdge(G1, 1, 0);
insertEdge(G1, 1, 2);
insertEdge(G1, 1, 3);
insertEdge(G1, 2, 1);
insertEdge(G1, 2, 3);
insertEdge(G1, 3, 0);
insertEdge(G1, 3, 1);
insertEdge(G1, 3, 2);
printf("\nG1의 인접행렬");
printf_adjMatrix(G1);
for(i=0;i<3;i++) {
insertVertex(G2, i);
}
insertEdge(G2, 0, 1);
insertEdge(G2, 0, 2);
insertEdge(G2, 1, 0);
insertEdge(G2, 1, 2);
insertEdge(G2, 2, 0);
insertEdge(G2, 2, 1);
printf("\n\nG2의 인접행렬");
printf_adjMatrix(G2);
for(i=0;i<4;i++) {
insertVertex(G3, i);
}
insertEdge(G3, 0, 1);
insertEdge(G3, 0, 3);
insertEdge(G3, 1, 2);
insertEdge(G3, 1, 3);
insertEdge(G3, 2, 3);
printf("\n\nG3의 인접행렬");
printf_adjMatrix(G3);
for(i=0;i<3;i++) {
insertVertex(G4, i);
}
insertEdge(G4, 0, 1);
insertEdge(G4, 0, 2);
insertEdge(G4, 1, 0);
insertEdge(G4, 1, 2);
printf("\n\nG4의 인접행렬");
printf_adjMatrix(G4);
getchar();
}
*/
#include <stdio.h>
void selectionSort(int a[], int size)
{
int i, j, t, min, tmp;
printf("정렬할 원소 : ");
for(t=0;t<size;t++) printf("%d ", a[t]);
printf("\n\n 선택 정렬 수행 \n");
for(i=0;i<size-1;i++) {
min=i;
for(j=i+1;j<size;j++) {
if(a[j]<a[min])
min=j;
}
tmp=a[i];
a[i]=a[min];
a[min]=tmp;
printf("\n%d단계 : ", i+1);
for(t=0;t<size;t++) {
printf("%3d ", a[t]);
}
}
}
int main()
{
int n, size=0, *arr;
FILE *fp;
fp=fopen("data.txt", "r");
arr=(int*)malloc(sizeof(int)*size);
if(fp==NULL) {
printf("ERROR");
return 0;
}
while(!feof(fp)) {
fscanf(fp, "%d", &n);
size++;
arr[size]=n;
}
selectionSort(arr[size], size);
}