user program excute IO -> I/O trap into i/o layer -> memory management layer -> cpu scheduling layer -> h/w
'IT 전공지식 > 운영체제(Operating System)' 카테고리의 다른 글
1. Overview (0) | 2011.06.22 |
---|
user program excute IO -> I/O trap into i/o layer -> memory management layer -> cpu scheduling layer -> h/w
1. Overview (0) | 2011.06.22 |
---|
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int iData;
struct node *npLink;
} NODE;
typedef struct queue
{
int iCount;
struct node *npFront;
struct node *npRear;
} QUEUE;
void insertQueue(QUEUE *qpQ, int iInData);
int deleteQueue(QUEUE *qpQ);
void printQeueu(QUEUE *qpQ);
int main()
{
QUEUE *qpQueue = (QUEUE*)malloc(sizeof(QUEUE));
qpQueue->iCount = 0;
qpQueue->npFront = NULL;
qpQueue->npRear = NULL;
insertQueue(qpQueue, 1);
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
insertQueue(qpQueue, 2);
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
insertQueue(qpQueue, 3);
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
insertQueue(qpQueue, 4);
printQeueu(qpQueue);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
return 0;
}
void insertQueue(QUEUE *qpQ, int iInData)
{
NODE *npNewNode = (NODE*)malloc(sizeof(NODE));
npNewNode->iData = iInData;
npNewNode->npLink = NULL;
if (qpQ->iCount == 0)
{
qpQ->npFront = npNewNode;
qpQ->npRear = npNewNode;
}
else
{
qpQ->npRear->npLink = npNewNode;
qpQ->npRear = npNewNode;
}
qpQ->iCount++;
}
int deleteQueue(QUEUE *qpQ)
{
NODE *npCurNode = NULL;
int iReData;
if (qpQ->iCount == 0)
{
printf("No Data!\n");
exit(1);
}
else
{
npCurNode = qpQ->npFront;
iReData = npCurNode->iData;
qpQ->npFront = npCurNode->npLink;
free(npCurNode);
qpQ->iCount--;
return iReData;
}
}
void printQeueu(QUEUE *qpQ)
{
NODE *npCurNode = NULL;
if (qpQ->iCount == 0)
{
printf("No Data!\n");
exit(1);
}
else
{
npCurNode = qpQ->npFront;
while (npCurNode != NULL)
{
printf("%d => ", npCurNode->iData);
npCurNode = npCurNode->npLink;
}
printf("NULL\n");
}
}
linked list 정렬입력 (0) | 2014.11.14 |
---|---|
linked list (0) | 2014.11.14 |
circular queue (0) | 2014.11.07 |
배열 스택 (0) | 2014.10.24 |
서브스트링 연산 (0) | 2014.10.23 |
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int iData;
struct node *nLink;
} NODE;
NODE *insertNode(NODE *t);
NODE *deleteNode(NODE *t);
void printNode(NODE *t);
int main()
{
NODE *nodelink = NULL;
int selectItem;
while (1)
{
system("cls");
printf("1.데이터 삽입\n");
printf("2.데이터 삭제\n");
printf("3.데이터 출력\n");
printf("4.종료\n");
scanf_s("%d", &selectItem);
switch (selectItem)
{
case 1:
nodelink = insertNode(nodelink);
break;
case 2:
nodelink= deleteNode(nodelink);
break;
case 3:
printNode(nodelink);
break;
case 4:
return 0;
default:
printf("잘못눌렸습니다\n");
break;
}
system("pause");
}
return 0;
}
NODE *insertNode(NODE *t)
{
NODE *curNode = t;
NODE *folNOde = t;
NODE *newNode = NULL;
newNode = (NODE*)malloc(sizeof(NODE));
printf("데이터를 입력하시오 : ");
scanf_s("%d", &newNode->iData);
newNode->nLink = NULL;
while ((curNode != NULL) && (curNode->iData < newNode->iData))
{
folNOde = curNode;
curNode = curNode->nLink;
}
newNode->nLink = curNode;
if (curNode == t)
{
t = newNode;
}
else
{
folNOde->nLink = newNode;
}
return t;
}
NODE *deleteNode(NODE *t)
{
NODE *curnode, *follnode;
int iFindData;
printf("삭제할 데이터를 입력하시오 : ");
scanf_s("%d", &iFindData);
curnode = t;
follnode = t;
while ((curnode != NULL) && (curnode->iData != iFindData))
{
follnode = curnode;
curnode = curnode->nLink;
}
if (curnode == NULL)
{
printf("삭제할 데이터가 없습니다.\n");
return t;
}
else if (curnode == t)
{
t = curnode->nLink;
}
else if (curnode->nLink == NULL)
{
follnode->nLink = NULL;
}
else
{
follnode->nLink = curnode->nLink;
}
free(curnode);
return t;
}
void printNode(NODE *t)
{
NODE * tempNode = t;
if (tempNode == NULL)
{
printf("출력할 데이터가 없습니다 \n");
return;
}
while (tempNode != NULL)
{
printf( "%d => ", tempNode->iData);
tempNode = tempNode->nLink;
}
printf("NULL\n");
}
linked list qeueu (0) | 2014.11.14 |
---|---|
linked list (0) | 2014.11.14 |
circular queue (0) | 2014.11.07 |
배열 스택 (0) | 2014.10.24 |
서브스트링 연산 (0) | 2014.10.23 |
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int iData;
struct node *nLink;
} NODE;
NODE *insertNode(NODE *t);
NODE *deleteNode(NODE *t);
void printNode(NODE *t);
int main()
{
NODE *nodelink = NULL;
int selectItem;
while (1)
{
printf("1.데이터 삽입\n");
printf("2.데이터 삭제\n");
printf("3.데이터 출력\n");
printf("4.종료\n");
scanf_s("%d", &selectItem);
switch (selectItem)
{
case 1:
nodelink = insertNode(nodelink);
break;
case 2:
nodelink= deleteNode(nodelink);
break;
case 3:
printNode(nodelink);
break;
case 4:
return 0;
default:
printf("잘못눌렸습니다\n");
break;
}
}
return 0;
}
NODE *insertNode(NODE *t)
{
NODE *curNode = t;
NODE *newNode = NULL;
newNode = (NODE*)malloc(sizeof(NODE));
printf("데이터를 입력하시오 : ");
scanf_s("%d", &newNode->iData);
newNode->nLink = NULL;
if(t==NULL)
{
t = newNode;
}
else
{
while (curNode->nLink != NULL)
{
curNode = curNode->nLink;
}
curNode->nLink = newNode;
}
return t;
}
NODE *deleteNode(NODE *t)
{
NODE *curnode, *follnode;
int iFindData;
printf("삭제할 데이터를 입력하시오 : ");
scanf_s("%d", &iFindData);
curnode = t;
follnode = t;
while ((curnode != NULL) && (curnode->iData != iFindData))
{
follnode = curnode;
curnode = curnode->nLink;
}
if (curnode == NULL)
{
printf("삭제할 데이터가 없습니다.\n");
return t;
}
else if (curnode == t)
{
t = curnode->nLink;
}
else if (curnode->nLink == NULL)
{
follnode->nLink = NULL;
}
else
{
follnode->nLink = curnode->nLink;
}
free(curnode);
return t;
}
void printNode(NODE *t)
{
NODE * tempNode = t;
if (tempNode == NULL)
{
printf("출력할 데이터가 없습니다 \n");
return;
}
while (tempNode != NULL)
{
printf( "%d => ", tempNode->iData);
tempNode = tempNode->nLink;
}
printf("NULL\n");
}
linked list qeueu (0) | 2014.11.14 |
---|---|
linked list 정렬입력 (0) | 2014.11.14 |
circular queue (0) | 2014.11.07 |
배열 스택 (0) | 2014.10.24 |
서브스트링 연산 (0) | 2014.10.23 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXQUEUE 6 /*큐의 길이*/
typedef struct{
char *queue[MAXQUEUE];
int front;
int rear;
} CQueueType;
CQueueType *CreatQueue(); /*Queue 만들기*/
int IsEmp(CQueueType *CQueue); /*Empty 인지 체크*/
int IsFull(CQueueType *CQueue); /*Full 인지 체크*/
void InsertQueue(CQueueType *CQueue); /*내용삽입*/
void DelItem(CQueueType *CQueue); /*Front의 항목을 삭제*/
char *RetItem(CQueueType *CQueue); /*Front의 항목을 반환*/
void PrintQueue(CQueueType *CQueue); /*Queue 안의 내용을 출력*/
char *InputItem(FILE *fInStr); /*아이템을 삽입*/
void isStringNum(char *cInStr); /*문자,숫자 확인*/
int main()
{
CQueueType *CQ1 = CreatQueue();
int iSelect;
while (1)
{
iSelect = 0;
system("cls");
printf("데이터를 5개까지 입력 가능한 Circular Queue 입니다\n");
printf("1. 데이터 삽입\n");
printf("2. 데이터 반환\n");
printf("3. 데이터 삭제\n");
printf("4. 데이터 확인\n");
printf("5. 종료\n");
printf("해당 값을 선택하십시오 : ");
scanf_s("%d", &iSelect);
fflush(stdin);
switch (iSelect)
{
case 1:
InsertQueue(CQ1);
break;
case 2:
printf("반환된 데이터는 : %s 입니다\n", RetItem(CQ1));
DelItem(CQ1);
break;
case 3:
DelItem(CQ1);
printf("데이터를 삭제하였습니다 \n");
break;
case 4:
printf("큐 내부의 데이터 입니다.\n");
PrintQueue(CQ1);
break;
case 5:
free(CQ1);
return 0;
default:
printf("입력값이 올바르지 않습니다.\n");
break;
}
system("pause");
}
}
CQueueType *CreatQueue()
{
CQueueType *CQueue;
CQueue = (CQueueType*)malloc(sizeof(CQueueType));
CQueue->front = 0;
CQueue->rear = 0;
return CQueue;
}
int IsEmp(CQueueType *CQueue) /*빈큐 확인*/
{
if (CQueue->front == CQueue->rear)
{
printf("Circular Queue is empty\n");
return 1;
}
else
{
return 0;
}
}
int IsFull(CQueueType *CQueue)
{
if (((CQueue->rear + 1) % MAXQUEUE) == CQueue->front)
{
printf("Circular Queue is Full\n");
return 1;
}
return 0;
}
void InsertQueue(CQueueType *CQueue)
{
char *ch=NULL;
if (IsFull(CQueue))
{
exit(1);
}
else
{
printf("데이터를 입력하십시오 : ");
CQueue->rear = (CQueue->rear + 1) % MAXQUEUE;
CQueue->queue[CQueue->rear] = InputItem(stdin);
}
}
void DelItem(CQueueType *CQueue)
{
if (IsEmp(CQueue))
{
exit(1);
}
else
{
CQueue->front = (CQueue->front + 1) % MAXQUEUE;
free(CQueue->queue[CQueue->front]);
}
}
char *RetItem(CQueueType *CQueue)
{
if (IsEmp(CQueue))
{
exit(1);
}
else
{
return CQueue->queue[CQueue->front + 1 % MAXQUEUE];
}
}
void PrintQueue(CQueueType *CQueue)
{
int iCount;
int iFirst;
int iLast;
iFirst = (CQueue->front + 1) % MAXQUEUE;
iLast = (CQueue->rear + 1) % MAXQUEUE;
printf("Circular Queue : ");
iCount = iFirst;
while (iCount != iLast)
{
printf("[%s] ", CQueue->queue[iCount]);
iCount = (iCount + 1) % MAXQUEUE;
}
printf("\n");
}
char *InputItem(FILE *fInStr)
{
char *cSring;
int iBuf;
int iLen = 1;
cSring = malloc(iLen*sizeof(char));
while ( (iBuf = fgetc(fInStr)) != EOF && iBuf != '\n')
{
cSring[iLen - 1] = iBuf;
cSring = (char*)realloc(cSring, ++iLen*sizeof(char));
cSring[iLen-1] = '\0';
}
isStringNum(cSring);
fflush(stdin);
return cSring;
}
void isStringNum(char *cInStr)
{
int iCount;
int iLenStr = strlen(cInStr);
if (iLenStr == 0)
{
printf("입력값이 없습니다");
return;
}
else
{
for (iCount = 0; iCount < iLenStr; iCount++)
{
if (cInStr[iCount] == '+' ||
cInStr[iCount] == '-' ||
cInStr[iCount] == '.')
{
continue;
}
if (cInStr[iCount] < '0' || cInStr[iCount] >'9')
{
printf("문자열 데이터를 입력하셨습니다\n");
return;
}
}
printf("숫자열 데이터를 입력하셨습니다\n");
}
}
linked list 정렬입력 (0) | 2014.11.14 |
---|---|
linked list (0) | 2014.11.14 |
배열 스택 (0) | 2014.10.24 |
서브스트링 연산 (0) | 2014.10.23 |
스트링 결합연산 (0) | 2014.10.23 |
#include <stdio.h>
#include <stdlib.h>
#define MAXSTACK 10
typedef struct stack
{
char *data[MAXSTACK];
int top;
} STACK;
void CheckStack(STACK *tmpStack);
char *PopStack(STACK *tmpStack);
void PushStack(STACK *tmpStack);
void PrintStack(STACK *tmpStack);
int main()
{
STACK *MainStack;
int iCount = 0;
char checkMet;
MainStack = (STACK*)malloc(sizeof(STACK));
MainStack->top = -1;
while (iCount < MAXSTACK)
{
MainStack->data[iCount] = NULL;
iCount++;
}
while (1)
{
system("cls");
printf("1. push \n");
printf("2. pop \n");
printf("3. print \n");
printf("4. end \n");
checkMet = getc(stdin);
fflush(stdin);
if (checkMet == '1')
{
printf("값을 입력해주세요 : ");
PushStack(MainStack);
}
else if (checkMet == '2')
{
printf("POP한 항목은 : %s\n", PopStack(MainStack));
}
else if (checkMet == '3')
{
PrintStack(MainStack);
}
else if (checkMet == '4')
{
return 0;
}
else
{
printf("입력값이 잘못되었습니다");
}
system("pause");
}
}
void CheckStack(STACK *tmpStack)
{
if (tmpStack->top == -1)
{
printf("Stack is empty");
}
else
{
printf("Stack is not empty");
}
}
char *PopStack(STACK *tmpStack)
{
char *tmpString;
if (tmpStack->top == -1)
{
printf("Stack is underflow");
exit(1);
}
tmpString = tmpStack->data[tmpStack->top];
//프린트 했을 때 보기 좋으라고 NULL 지정
//본래라면 그냥 덮어씌어지고, 스택포인트 때문에 전혀 상관없음;
tmpStack->data[tmpStack->top] = NULL;
tmpStack->top--;
return tmpString;
}
void PushStack(STACK *tmpStack)
{
int iBuf;
int iLen = 1;
char *tmpString = (char*)malloc(sizeof(char));
if (tmpStack->top > MAXSTACK-1)
{
printf("Stack is overflow");
exit(1);
}
while ((iBuf = fgetc(stdin)) != EOF && iBuf != '\n')
{
tmpString[iLen - 1] = iBuf;
tmpString = (char*)realloc(tmpString, (++iLen));
}
tmpString = (char*)realloc(tmpString, (--iLen));
tmpString[iLen] = '\0';
tmpStack->data[++tmpStack->top] = tmpString;
}
void PrintStack(STACK *tmpStack)
{
int iCount = 9;
while (iCount > -1)
{
printf("[%d] 번째 값 : %s\n", iCount, tmpStack->data[iCount]);
iCount--;
}
}
linked list 정렬입력 (0) | 2014.11.14 |
---|---|
linked list (0) | 2014.11.14 |
circular queue (0) | 2014.11.07 |
서브스트링 연산 (0) | 2014.10.23 |
스트링 결합연산 (0) | 2014.10.23 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * substr(char * s1, int i, int j);
int main()
{
char *s1 = "abcde";
char *s2;
s2 = substr(s1, 1, 4);
printf("%s\n", s2);
//free(s2);
return 0;
}
char * substr(char * s1, int i, int j)
{
int k, limit;
char *temp;
temp = (char*)malloc(j);
limit = i + j;
for (k = i; k < limit; k++)
{
temp[k - i] = s1[k];
}
temp[j] = '\0';
return temp;
}
linked list 정렬입력 (0) | 2014.11.14 |
---|---|
linked list (0) | 2014.11.14 |
circular queue (0) | 2014.11.07 |
배열 스택 (0) | 2014.10.24 |
스트링 결합연산 (0) | 2014.10.23 |
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *concate(char *s1, char *s2);
int main()
{
char *s1 = "aaa";
char *s2 = "bbb";
char *s3;
s3 = concate(s1, s2);
printf("%s\n", s3);
}
char *concate(char *s1, char *s2)
{
char *s3;
int len1, len2, len3, i;
len1 = strlen(s1);
len2 = strlen(s2);
len3 = len1 + len2;
s3 = (char*)malloc(len3 + 1);
i = 0;
while (*s1!='\0')
{
s3[i++] = *s1;
s1++;
}
while (*s2 != '\0')
{
s3[i++] = *s2;
s2++;
}
s3[i] = '\0';
return s3;
}
linked list 정렬입력 (0) | 2014.11.14 |
---|---|
linked list (0) | 2014.11.14 |
circular queue (0) | 2014.11.07 |
배열 스택 (0) | 2014.10.24 |
서브스트링 연산 (0) | 2014.10.23 |
user program excute (0) | 2015.01.30 |
---|