'대학 수강과목 > 자료구조' 카테고리의 다른 글
[자료구조]기말고사 대비 시험문제 필기/실기(답포함) 비번:내생일 (0) | 2014.12.10 |
---|---|
[자료구조]11/27 예제 변형 2 (0) | 2014.11.27 |
[자료구조]11/27 예제 변형 (0) | 2014.11.27 |
[자료구조]11/27 튜터링 (0) | 2014.11.27 |
[자료구조] 7장 8번 (0) | 2014.11.06 |
[자료구조]기말고사 대비 시험문제 필기/실기(답포함) 비번:내생일 (0) | 2014.12.10 |
---|---|
[자료구조]11/27 예제 변형 2 (0) | 2014.11.27 |
[자료구조]11/27 예제 변형 (0) | 2014.11.27 |
[자료구조]11/27 튜터링 (0) | 2014.11.27 |
[자료구조] 7장 8번 (0) | 2014.11.06 |
[자료구조]기말고사 대비 시험문제 필기/실기(답포함) 비번:내생일 (0) | 2014.12.10 |
---|---|
[자료구조]11/27 디버깅 (0) | 2014.11.27 |
[자료구조]11/27 예제 변형 (0) | 2014.11.27 |
[자료구조]11/27 튜터링 (0) | 2014.11.27 |
[자료구조] 7장 8번 (0) | 2014.11.06 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct ListNode{ //단순연결리스트의 노드 구조 정의
char data[10];
struct ListNode* link;
} listNode;
typedef struct{ //리스트의 헤드 노드의 구조 정의
listNode* head;
} linkedList_h;
linkedList_h* createLinkedList_h(void);
void freeLinkedList_h(linkedList_h*);
void addLastNode(linkedList_h*, char*);
void reverse(linkedList_h*);
void deleteLastNode(linkedList_h*);
void printList(linkedList_h*);
linkedList_h* createLinkedList_h(void){ //공백 연결리스트 생성 연산
linkedList_h* L;
L = (linkedList_h*)malloc(sizeof(linkedList_h)); //헤드 노드 할당
//1; //공백 리스트이므로 NULL 설정
return L;
}
void addLastNode(linkedList_h* L, char* x){ //리스트의 마지막 노드 삽입 연산
listNode* newNode;
listNode* p;
newNode = (listNode*)malloc(sizeof(listNode)); //삽입할 새 노드 할당
strcpy(newNode->data, x); //새 노드의 데이터 필드에 x 저장
newNode->link= NULL;
if (L->head == NULL){ //현재 리스트가 공백인 경우 :
//2;
return;
}
p = L->head;
while (p->link != NULL) p = p->link;
p ->link = newNode;
}
void reverse(linkedList_h * L){ //리스트의 노드 순서를 역순으로 바꾸는 연산
listNode* p;
listNode* q;
listNode* r;
p = L->head;
q=NULL;
r=NULL;
while (p!= NULL){ //노드의 연결을 반대로 바꾸기
r = q;
q = p;
p = //3;//다음 노드로 이동
q->link = r;
}
L->head = q;
}
void deleteLastNode(linkedList_h * L){ //리스트의 마지막 노드 삭제 연산
listNode* previous;
listNode* current;
if (L->head == NULL) return; //공백 리스트인 경우, 삭제 연산 중단
if (L->head->link == NULL) { //리스트에 노드가 한 개만 있는 경우,
free(L->head); // 첫 번째 노드를 메모리 해제하고
L->head = NULL; // 리스트 시작 포인터를 null로 설정한다.
return;
}
else { //리스트에 노드가 여러 개 있는 경우,
previous = L->head;
current = L->head->link;
while(current ->link != NULL){
previous = current;
current = current->link;
}
free(current);
previous->link = NULL;
}
}
void freeLinkedList_h(linkedList_h* L){ //리스트 전체 메모리 해제 연산
//4
}
void printList(linkedList_h* L){ //노드 순서대로 리스트를 출력하는 연산
listNode* p;
printf("L = (");
p= L->head;
while(p != NULL){
printf("%s", p->data);
p = p->link;
if(p != NULL) printf(", ");
}
printf(") \n");
}
int main(){
linkedList_h* L;
L = createLinkedList_h();
printf("(1) 공백 리스트 생성하기! \n");
printList(L); getchar();
printf("(2) 리스트에 3개의 노드 추가하기! \n");
addLastNode(L, "월");
addLastNode(L, "수");
addLastNode(L, "금");
printList(L); getchar();
printf("(3) 리스트 마지막에 노드 한개 추가하기! \n");
addLastNode(L, "일");
printList(L); getchar();
printf("(4) 마지막 노드 삭제하기! \n");
deleteLastNode(L);
printList(L); getchar();
printf("(5) 리스트 원소를 역순으로 변환하기! \n");
reverse(L);
printList(L); getchar();
printf("(6) 리스트 공간을 해제하여, 공백 리스트 상태로 만들기! \n");
freeLinkedList_h(L);
printList(L);
getchar();
return 0;
}
[자료구조]11/27 디버깅 (0) | 2014.11.27 |
---|---|
[자료구조]11/27 예제 변형 2 (0) | 2014.11.27 |
[자료구조]11/27 튜터링 (0) | 2014.11.27 |
[자료구조] 7장 8번 (0) | 2014.11.06 |
#2. 배수, 공배수, 최소공배수 (0) | 2014.09.03 |
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#define cQ_SIZE 15
int count=0;
typedef struct treeNode{ //연결 자료구조로 구성하기 위해 트리의 노드 정의
char data;
struct treeNode *left; //왼쪽 서브트리에 대한 링크 필드
struct treeNode *right; //오른쪽 서브트리에 대한 링크 필드
}element;
//char형을 큐 element의 자료형으로 정의
typedef struct{
element queue[cQ_SIZE]; //1차원 배열 큐 선언
int front, rear;
} cQueueType;
cQueueType *createQueue()
{
cQueueType *cQ;
cQ = (cQueueType *)malloc(sizeof(cQueueType));
cQ->front=0; //원형 큐의 front 초기값 설정
cQ->rear=0; //원형 큐의 rear 초기값 설정
return cQ;
}
int isEmpty(cQueueType *cQ) //원형 큐가 공백인지 확인하는 연산
{
if (cQ->front == cQ->rear) {
printf("\n Circular Queue is empty! \n");
return 1;
}
else return 0;
}
int isFull(cQueueType *cQ)
{
if (((cQ->rear + 1) % cQ_SIZE) == cQ->front) {
printf("\n Circular Queue is full! \n");
return 1;
}
else return 0;
}
void enQueue(cQueueType *cQ, element item) //원형 큐의 rear에 원소를 삽입하는 연산
{
if(isFull(cQ)) exit(1);
else {
cQ->rear = (cQ->rear + 1) % cQ_SIZE;
cQ->queue[cQ->rear] = item;
}
}
element deQueue(cQueueType *cQ) //원형 큐의 front에서 원소를 삭제하고 반환하는 연산
{
if (isEmpty(cQ)) exit(1);
else {
cQ->front = (cQ->front + 1) % cQ_SIZE;
return cQ->queue[cQ->front];
}
}
void del(cQueueType *cQ) //원형 큐의 front에서 원소를 삭제하는 연산
{
if (isEmpty(cQ)) exit(1);
else cQ->front = (cQ->front + 1) % cQ_SIZE;
}
typedef struct treeNode{ //연결 자료구조로 구성하기 위해 트리의 노드 정의
char data;
struct treeNode *left; //왼쪽 서브트리에 대한 링크 필드
struct treeNode *right; //오른쪽 서브트리에 대한 링크 필드
}treeNode;
treeNode* makeRootNode(char data, treeNode* leftNode, treeNode* rightNode)
{ //data를 루트 노드로 하여 왼쪽 서브트리와 오른쪽 서브트리를 연결하는 연산
treeNode* root = (treeNode *)malloc(sizeof(treeNode));
root->data = data;
root->left = leftNode;
root->right = rightNode;
return root;
}
void preorder(treeNode* root) //이진 트리에 대한 전위 순회 연산
{
if(root){
printf("%c", root->data);
preorder(root->left);
preorder(root->right);
}
}
void inorder(treeNode* root) //이진 트리에 대한 중위 순회 연산
{
if(root){
inorder(root->left);
printf("%c", root->data);
inorder(root->right);
}
}
void postorder(treeNode* root) //이진 트리에 대한 후위 순회 연산
{
if(root){
postorder(root->left);
postorder(root->right);
printf("%c", root->data);
}
}
void levelOrder(treeNode* root)
{
cQueueType *cQ1 = createQueue();
enQueue(cQ1, *root);
element temp;
while(cQ1->front != cQ1->rear){
temp = deQueue(cQ1);
if(temp.left)
enQueue(cQ1, *temp.left);
if(temp.right)
enQueue(cQ1, *temp.right);
printf("%c ", temp.data);
}
}
void main()
{
treeNode* n9 = makeRootNode('8', NULL, NULL);
treeNode* n8 = makeRootNode('7', NULL, NULL);
treeNode* n7 = makeRootNode('6', NULL, NULL);
treeNode* n6 = makeRootNode('5', NULL, n9);
treeNode* n5 = makeRootNode('4', NULL, NULL);
treeNode* n4 = makeRootNode('3', n7, n8);
treeNode* n3 = makeRootNode('2', n5, n6);
treeNode* n2 = makeRootNode('1', n4, NULL);
treeNode* n1 = makeRootNode('0', n2, n3);
printf("\n preorder : ");
preorder(n1);
printf("\n inorder : ");
inorder(n1);
printf("\n postorder : ");
postorder(n1);
printf("\n levelOrder : ");
levelOrder(n1);
getchar();
}
[자료구조]11/27 예제 변형 2 (0) | 2014.11.27 |
---|---|
[자료구조]11/27 예제 변형 (0) | 2014.11.27 |
[자료구조] 7장 8번 (0) | 2014.11.06 |
#2. 배수, 공배수, 최소공배수 (0) | 2014.09.03 |
#1. 순서도 과제 (0) | 2014.09.03 |
[자료구조]11/27 예제 변형 2 (0) | 2014.11.27 |
---|---|
[자료구조]11/27 예제 변형 (0) | 2014.11.27 |
[자료구조]11/27 튜터링 (0) | 2014.11.27 |
#2. 배수, 공배수, 최소공배수 (0) | 2014.09.03 |
#1. 순서도 과제 (0) | 2014.09.03 |
9/27 실습1
배수 구하기
결과
9/27 실습2
최소공배수 구하기
결과
[자료구조]11/27 예제 변형 2 (0) | 2014.11.27 |
---|---|
[자료구조]11/27 예제 변형 (0) | 2014.11.27 |
[자료구조]11/27 튜터링 (0) | 2014.11.27 |
[자료구조] 7장 8번 (0) | 2014.11.06 |
#1. 순서도 과제 (0) | 2014.09.03 |
문제 1: 교재 83쪽 연습문제 #25, #28. (28문제 수정 ?)
문제 2. 순서도에서 보았던 PrintGugu() 함수의 순서도를 다음 3 가지 방법으로 가상코드로 작성하시오.
1. for 이용
2. while 이용
3. do while 이용
PrintGuGu( )
I <- 0
J <- 0
여기에 가상코드 작성
end
제출방법: 손으로 그린 후에 하나의 스캔파일로 디지털캠퍼스에 제출
copy 시 불이익에 대해 책임지지 않음.
[자료구조]11/27 예제 변형 2 (0) | 2014.11.27 |
---|---|
[자료구조]11/27 예제 변형 (0) | 2014.11.27 |
[자료구조]11/27 튜터링 (0) | 2014.11.27 |
[자료구조] 7장 8번 (0) | 2014.11.06 |
#2. 배수, 공배수, 최소공배수 (0) | 2014.09.03 |