1. Selection Sort

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <limits.h>

#define SIZE 1000

int a[SIZE];

int swap(int *a, int *b) {
	int temp = *a;
	*a = *b;
	*b = temp;
}

int main(void) {
	int n, min, index;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	for (int i = 0; i < n; i++) {
		min = INT_MAX;
		for (int j = i; j < n; j++) {
			if (min > a[j]) {
				min = a[j];
				index = j;
			}
		}
		swap(&a[i], &a[index]);
	}
	for (int i = 0; i < n; i++) {
		printf("%d", a[i]);
	}
	system("pause");
	return 0;
}

 

2. Insertion Sort

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <limits.h>

#define SIZE 1000

int a[SIZE];

int swap(int *a, int *b) {
	int temp = *a;
	*a = *b;
	*b = temp;
}

int main(void) {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	for (int i = 0; i < n - 1; i++) {
		int j = i;
		while (j >= 0 && a[j] > a[j + 1]) {
			swap(&a[j], &a[j + 1]);
			j--;
		}
	}


	for (int i = 0; i < n; i++) {
		printf("%d", a[i]);
	}
	system("pause");
	return 0;
}

 

be the happy Gosu.

woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

반응형

'ETC > C, C++' 카테고리의 다른 글

[C, C++] Counting Sort  (2) 2022.02.09
[C, C++] Queue in Array, Linked List  (0) 2021.10.20
[C, C++] Stack in Array, Lined List  (0) 2021.10.20
[C, C++] Sorted Doubly Linked List  (0) 2021.10.20
python -V

Anaconda 에 Tensorflow 를 설치하는 방법입니다.

Jupyter notebook 을 사용중 Tensorflow 가 설치되지 않았다는 오류메세지가 나타난다면 Tensorflow 를 설치해야합니다.

일단 Anaconda 의 Prompt 를 실행시킵니다.

Select Anaconda Prompt.

python -V

를 입력하여 python 의 버전을 확인합니다.

그리고 일단

pip install --upgrade pip

를 입력하여 pip 를 upgrade 해줍니다.

## conda create -n tensorflow pip python={python 버전}

conda create -n tensorflow pip python=3.8

조금전에 확인한 python 버전과 함께 위 명령을 입력하여 Anaconda 에 Tensorflow 만의 가상의 사용공간을 생성해줍니다.

conda activate tensorflow

생성한 가상공간을 활성화 시킵니다.

 

이제 Tensorflow 를 설치합니다.

# CPU Version 으로 설치하려면
pip install --ignore-installed --upgrade tensorflow-cpu

# GPU Version 으로 설치하려면
pip install --ignore-installed --upgrade tensorflow-gpu


# CPU / GPU stable release version (CPU/GPU 통합버전)으로 설치하려면
pip install tensorflow

# 특정 version 으로 설치하려면
pip install tensorflow=-1.92

# unstable preview version (Preview version)으로 설치하려면
pip install tf-nightly

사용하는 network 환경에 방화벽이 설치되어 있는 경우 다음과 같은 오류가 발생한다.

connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

이런 경우에는

# 다음 명령문을 conda install 전에 입력한다.
conda config --set ssl_verify false
conda install pip tensorflow

또는 

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org tensorflow

를 실행한다.

다음과 같은 오류가 발생한 경우라면

ERROR: Could not install packages due to an OSError: [WinError 5] 액세스가 거부되었습니다:

Anaconda prompt 를 "관리자 권한으로 실행" 으로 실행하여 진행한다.

설치 후 prompt 에서 tensorflow version 을 확인한다.

# python 실행
python

# Tensorflow version 확인
import tensorflow as tf
# _ _ 두번 입력주의
tf.__version__

# python 종료
exit()

 

행복한 고수되세요.

woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

반응형

1. Queue in Array

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

#define SIZE 10000
#define INF		99999

int queue[SIZE];
int front = 0;
int rear = 0;

void push(int data) {
	if (rear >= SIZE - 1) {
		printf("Queue Overflow !!");
		return;
	}
	queue[rear++] = data;
}

int pop() {
	if (front == rear) {
		printf("Queue Underflow !!");
		return -INF;
	}

	return queue[front++];
}

void show() {
	printf("Front Of Queue \n");
	for (int i = front; i < rear; i++) {
		printf("%d \n", queue[i]);
	}
	printf("Rear Of Queue \n");
}

int main() {
	push(2);
	push(1);
	push(5);
	push(7);
	push(6);
	pop();
	push(8);
	pop();
	push(3);
	show();
	system("pause");
}

 

2. Queue in LinkedList

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

#define INF		99999

typedef struct {
	int data;
	struct Node *next;
}Node;

typedef struct {
	struct Node *front;
	struct Node *rear;
	int count;
} Queue;

void push(Queue *queue, int data) {
	Node *node = (Node*)malloc(sizeof(Node));
	node->data = data;
	node->next = NULL;

	if (queue->count == 0) {
		queue->front = node;
	}
	else {		  
		Node *rearNode = (Node*)malloc(sizeof(Node));
		rearNode = queue->rear;
		rearNode->next = node;
	}			  
	queue->rear = node;	
	queue->count++;
}

int pop(Queue *queue) {
	if (queue->count == 0) {
		printf("Queue underflow !! \n");
		return -INF;
	}

	Node *node = (Node*)malloc(sizeof(Node));
	node = queue->front;
	int data = node->data;
	queue->front = node->next;
	free(node);

	queue->count--;
	return data;
}

void show(Queue *queue) {
	if (queue->count == 0) {
		printf("No data in Queue !! \n");
		return -INF;
	}

	Node* cur = queue->front;

	printf("Front Of Queue \n");
	while (cur != NULL) {
		printf("%d \n", cur->data);
		cur = cur->next;
	}
	printf("Rear Of Queue \n");
}

int main() {
	Queue queue;
	queue.count = 0;
	queue.front = NULL;
	queue.rear = NULL;

	push(&queue, 2);
	push(&queue, 1);
	push(&queue, 5);
	push(&queue, 7);
	push(&queue, 6);
	pop(&queue);
	push(&queue, 8);
	pop(&queue);
	push(&queue, 3);
	show(&queue);
	system("pause");
	return 0;
}

 

be the happy Gosu.

woojja ))*

반응형

'ETC > C, C++' 카테고리의 다른 글

[C, C++] Counting Sort  (2) 2022.02.09
[C, C++] Selection Sort, Insertion Sort  (0) 2021.11.04
[C, C++] Stack in Array, Lined List  (0) 2021.10.20
[C, C++] Sorted Doubly Linked List  (0) 2021.10.20

+ Recent posts