Skip to content
Main 함수
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream> #include <malloc.h> struct node{ int data; struct node *next; }; struct node *head = NULL; int main(int argc, char** argv) { insertSort(); printList(); freeList(); return 0; } |
Insertion Sort
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 31 32 33 34 35 36 37 38 39
|
void insertSort(){ int A[8] = {36, 2, 3, 15, 32, 4, 10, 30}; int n = sizeof(A) / sizeof(A[0]); head = NULL; for(int i=0; i<n; i++){ struct node *newNode = (struct node *)malloc(sizeof(struct node)); newNode->data = A[i]; newNode->next = NULL; struct node *cur; if(head == NULL){ head = newNode; } else{ cur = head; if(newNode->data < head->data){ head = newNode; newNode->next = cur; } else{ while(1){ if(cur->next == NULL){ cur->next = newNode; break; } else{ if(newNode->data < cur->next->data){ newNode->next = cur->next; cur->next = newNode; break; } cur = cur->next; } } } } } } |
링크드리스트 출력
|
void printList(){ //top부처 0의 순으로 출력 struct node *ptr = head; while(ptr != NULL){ printf("%d ", ptr->data); ptr = ptr->next; } printf("\n"); } |
할당 메모리 해제
|
void freeList(){ struct node *ptr = NULL; while(head != NULL){ ptr = head; head = head->next; free(ptr); } } |
Gpro 루팅 준비 1. 동기화 프로그램 및 usb 드라이버 다운로드 및 설치 2. window용 adb 다운로드 3. 루팅에 필요한 core파일 다운로드 루팅 과정 1. 휴대폰에서 usb 디버깅 체크(디버깅이 보이지 않는경우, 설정->휴대폰정보->소프트웨어정보->빌드번호 10회이상 터치) 2. pc와 휴대폰 연결 3. cmd 관리자 권한으로 실행 4. adb 다운받은 위치로 이동 (cd c:\download) 5.… Continue Reading LG Gpro 개발자모드 추가
애드몹 (http://kr.admob.com/)에 가입한다. 애드몹에 배너 광고 또는 전면 광고를 생성한다. Manifest.xml 파일에 다음 내용 추가
|
<manifest ...> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application ...> ... <activity android:name="com.google.android.gsm.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent"/> </application> </manifest> |
배너광고달기 activity_main.xml 파일에 다음 내용 추가
|
<com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" ads:adUnitId="@string/ad_unit_id" ads:adSize="BANNER" /> |
MainActivity.java 파일의 onCreate() 메소드에 다음 내용 추가
|
protected void onCreate(Bundle savedInstanceState) { ... AdView adView = (AdView) this.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest); } |
전면광고 달기 MainActivity.java 파일의 onCreate() 메소드에 다음 내용 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
private InterstitialAd m_fullAds; //전면광고 protected void onCreate(Bundle savedInstanceState) { ... m_fullAds = new InterstitialAd(this); m_fullAds.setAdUnitId(getString(R.string.FULL_AD_UNIT_ID)); AdRequest adRequest2 = new AdRequest.Builder().build(); m_fullAds.loadAd(adRequest2); /*fullAds.setAdListener(new AdListener() { @Override public void onAdLoaded() { Log.i("MY_TAG", "Complete.."); //f_displayFullAds(); super.onAdLoaded(); } });*/ } private void f_displayFullAds(){ if(m_fullAds != null && m_fullAds.isLoaded()){ m_fullAds.show(); } } |
onKeyDown() 메소드를 사용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(event.getAction() == KeyEvent.ACTION_DOWN){ if(keyCode == KeyEvent.KEYCODE_BACK){ //Toast.makeText(this, "test", Toast.LENGTH_SHORT).show(); new AlertDialog.Builder(this) .setTitle("종료확인") .setMessage("정말로 종료하시겠습니까?") .setPositiveButton("예", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }) .setNegativeButton("아니오", null) .create().show(); } } return super.onKeyDown(keyCode, event); } |
큐 참조 : http://terms.naver.com/entry.nhn?docId=2270426&cid=51173&categoryId=51173 큐(Queue) 출처 : http://terms.naver.com/entry.nhn?docId=834442&cid=42344&categoryId=42344 환형 큐/원형 큐(Circular Queue) 출처 : https://en.wikipedia.org/wiki/Circular_buffer main() 함수
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
|
#include <iostream> #include <malloc.h> struct node{ int data; struct node *next; }; struct node *frontList = NULL; struct node *rearList = NULL; int main(int argc, char** argv) { for(int i=0; i<12; i++){ insertList(i+11); printList(); } for(int i=0; i<6; i++){ deleteList(); printList(); } for(int i=0; i<12; i++){ insertList(i+11); printList(); } freeList(); return 0; } |
insertList() 함수
|
void insertList(int v){ struct node *ptr = (struct node *)malloc(sizeof(struct node)); ptr->data = v; ptr->next = NULL; if(frontList == NULL && rearList == NULL){ frontList = rearList = ptr; } else{ rearList->next = ptr; rearList = ptr; } } |
deleteList() 함수
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int deleteList(){ int v = 0; if(frontList == NULL) { printf("Empty.\n"); } else{ struct node* ptr = frontList; v = frontList->data; if(frontList == rearList) { frontList = rearList = NULL; } else { frontList = frontList->next; } free(ptr); } return v; } |
printList() 함수
|
void printList(){ //top부처 0의 순으로 출력 struct node *ptr = frontList; while(ptr != NULL){ printf("%d ", ptr->data); ptr = ptr->next; } printf("\n"); } |
freeList() 함수 : 프로그램을 종료하기전에 할당된 메모리 모두를 제거
|
void freeList(){ struct node *ptr = frontList; while(ptr != NULL){ frontList = frontList->next; free(ptr); ptr = frontList; } } |
스택 출처 : http://terms.naver.com/entry.nhn?docId=2837556&cid=40942&categoryId=32841 main() 함수
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream> #include <malloc.h> struct node{ int data; struct node *next; }; struct node *head = NULL; int main(int argc, char** argv) { for(int i=0; i<12; i++){ pushList(i+11); printList(); } for(int i=0; i<6; i++){ popList(); printList(); } for(int i=0; i<12; i++){ pushList(i+11); printList(); } freeList(); return 0; } |
pushList() 함수
|
void pushList(int v){ struct node *p = (struct node *)malloc(sizeof(struct node)); p->data = v; p->next = head; head = p; } |
popList() 함수
|
int popList(){ int v = 0; struct node *p = head; if(p == NULL){ printf("Empty.\n"); } else{ v = p->data; head = p->next; free(p); } } |
printList()함수 : 스택에 저장된 값들을 출력
|
void printList(){ //top부처 0의 순으로 출력 struct node *p = head; while(p != NULL){ printf("%d ", p->data); p = p->next; } printf("\n"); } |
freeList() 함수 : 프로그램을 종료하기전에 할당된 메모리 모두를 제거
|
void freeList(){ struct node *p = NULL; while(head != NULL){ p = head; head = head->next; free(p); } } |
원형큐/환형큐 환형 큐/원형 큐(Circular Queue) 출처 : https://en.wikipedia.org/wiki/Circular_buffer 사용하려는 큐에 10개의 값을 넣으려면 큐의 크기는 11만큼의 배열을 만들어야 한다. 큐가 비어있는지 꽉차있는지를 판단하기 위해 1개의 인덱스(보통 첫 번째 인덱스)는 항상 비워두어야 하기 때문이다. main() 함수
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#define MAX 10 int queue[MAX]; int front=0; int rear=0; int main(int argc, char** argv) { for(int i=0; i<12; i++){ insertCirQueue(i+11); printQueue(); } for(int i=0; i<6; i++){ deleteCirQueue(); printQueue(); } for(int i=0; i<12; i++){ insertCirQueue(i+11); printQueue(); } return 0; } |
insertCirQueue() 함수
|
void insertCirQueue(int v){ if((rear+1) % MAX == front ){ printf("Overflow.\n"); } else{ rear = (rear + 1) % MAX; queue[rear] = v; } } |
deleteCirQueue() 함수
|
int deleteCirQueue(){ int v = 0; if(front == rear){ printf("Empty.\n"); } else{ front = (front + 1) % MAX; v = queue[front]; } return v; } |
printQueue() 함수
|
void printQueue(){ int cnt = (rear - front + MAX) % MAX; printf("front(%2d), rear(%2d) : ", front, rear); for(int i=0; i<cnt; i++){ printf("%d ", queue[(front+i+1)%MAX]); } printf("\n"); } |
큐 참조 : http://terms.naver.com/entry.nhn?docId=2270426&cid=51173&categoryId=51173 큐(Queue) 출처 : http://terms.naver.com/entry.nhn?docId=834442&cid=42344&categoryId=42344 환형 큐/원형 큐(Circular Queue) 출처 : https://en.wikipedia.org/wiki/Circular_buffer main() 함수
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#define MAX 10 int queue[MAX]; int front=0; int rear=0; int main(int argc, char** argv) { for(int i=0; i<12; i++){ insertQueue(i+11); printQueue(); } for(int i=0; i<6; i++){ deleteQueue(); printQueue(); } for(int i=0; i<12; i++){ insertQueue(i+11); printQueue(); } return 0; } |
insertQueue() 함수
|
void insertQueue(int v){ if(rear == MAX-1){ printf("Overflow.\n"); } else{ rear++; queue[rear] = v; } } |
deleteQueue() 함수
|
int deleteQueue(){ int v = 0; if(front == rear){ printf("Empty.\n"); } else{ front++; v = queue[front]; } return v; } |
printQueue() 함수
|
void printQueue(){ int cnt = (rear - front + MAX) % MAX; printf("front(%2d), rear(%2d) : ", front, rear); for(int i=0; i<cnt; i++){ printf("%d ", queue[(front+i+1)%MAX]); } printf("\n"); } |
스택 출처 : http://terms.naver.com/entry.nhn?docId=2837556&cid=40942&categoryId=32841 main() 함수
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#define MAX 10 int stack[MAX]; int top=-1; int main(int argc, char** argv) { for(int i=0; i<12; i++){ push(i+11); printStack(); } for(int i=0; i<12; i++){ pop(); printStack(); } for(int i=0; i<12; i++){ push(i+11); printStack(); } return 0; } |
push() 함수
|
void push(int v){ if(top == MAX-1){ printf("Overflow.\n"); } else{ top++; stack[top] = v; } } |
pop() 함수
|
int pop(){ int v = 0; if(top == -1){ printf("Empty.\n"); } else{ v = stack[top]; top--; } return v; } |
printStack()함수 : 스택에 저장된 값들을 출력
|
void printStack(){ printf("top(%2d) : ", top); for(int i=0; i<=top; i++){ printf("%d ", stack[i]); } printf("\n"); } |
error: Content is protected !!