티스토리 뷰
- 삽입정렬
 
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
	freopen("input.txt", "rt", stdin);
	int n, i, j, tmp;
	int a[101];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	for(i=1; i<n; i++){
		tmp=a[i];
		for(j=i-1; j>=0; j--){
			if(a[j]>tmp) a[j+1]=a[j];
			else {
				break;
			}
		}
		a[j+1]=tmp;
	}
	for(i=0; i<n; i++){
		printf("%d ", a[i]);		
	}
	return 0;
}
- Special sort
 
#include<stdio.h>
int main() {
	freopen("input.txt", "rt", stdin);
	int a[101], n, tmp, min, i, j;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	for(i=0; i<n-1; i++){
		for(j=0; j<n-i-1; j++){
			if(a[j]>0 && a[j+1]<0){
				tmp=a[j];
				a[j]=a[j+1];
				a[j+1]=tmp;
			}
		}
	}
	for(i=0; i<n; i++){
		printf("%d ", a[i]);
	}
	return 0;
}'algorithm' 카테고리의 다른 글
| [c++] 두배열합치기 (0) | 2020.12.23 | 
|---|---|
| [c++] Least Recently Used, Inversion Sequence (0) | 2020.12.22 | 
| [c++] 3등의 성적은, 버블정렬 (0) | 2020.12.14 | 
| [c++] 탄화수소 질량, 선택정렬 (0) | 2020.12.13 | 
| [c++] 3의 개수구하기(large) (0) | 2020.12.11 | 
					댓글
						
					
					
					
				
			
										공지사항
										
								
							
								
								
									최근에 올라온 글
									
							
								
								
									최근에 달린 댓글
									
							
								
								- Total
 
- Today
 
- Yesterday
 
									링크
									
							
								
								
									TAG
									
							
								
								- server side rendering
 - stackframe
 - Stack
 - 배열
 - client side rendering
 - 세마포어
 - 알고리즘
 - 입출력장치
 - javascript
 - 병행프로세스
 - 인접리스트
 - Java
 - 운영체제
 - dfs
 - 구조체
 - 스텍
 - 동적프로그래밍
 - 교착상태
 - 퀵정렬
 - 재귀함수
 - 인접행렬
 - react
 - 이진탐색
 - 소프트웨어
 - 자료구조
 - 클래스
 - 최단경로
 - C++
 - BFS
 - C
 
| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
									글 보관함
									
							
					