블로그 이미지
Draw my Dream
꿈을드림

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

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
  • total
  • today
  • yesterday
2009. 4. 27. 14:16 Algorithm
자료구조 3번 문제였다.

앞으로도 들어가고 뒤로도 들어가는 구조의 자료형태를 만드시오.. 단, 나오는 곳은 뒤로 나온다.
문제는 앞으로 들어가면 앞으로 쌓이고 뒤에는 뒤로 쌓인다는 것 그래서 앞으로 들어갈때.. 모든 데이터를 밀어 줘야 한다는 거... ㅋㅋ
역시 스택이랑 비슷하다...

소스는 다음과 같다.


'Algorithm' 카테고리의 다른 글

Double Stack Program  (0) 2009.04.27
C언어 야구게임 (싱글 링크드 리스트 사용)  (0) 2009.04.10
C언어 Pointer에 대해.. #1  (0) 2009.03.16
BFS 알고리즘  (0) 2008.11.20
전산언어2 1분반 C Programming #23 실습문제1  (0) 2008.11.19
posted by 꿈을드림
2009. 4. 27. 14:13 Algorithm
이번 2009 자료구조 중간고사 문제중에 하나...
더블 스택 구현
5개의 구조체 배열에 학번, 이름을 넣을 수 있는 앞뒤의 Stack 구조이다.

소스는 다음과 같다.

posted by 꿈을드림
2009. 4. 10. 02:26 Algorithm
/* 심심해서 만들어 본 야구 게임 */

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAX 50
#define COT 25

typedef struct list* list_p;

typedef struct list {
 int a[MAX];
 int s;
 int b;
 int o;
 list_p next;
};

list_p head=NULL;

void rand_su(int num,int *p);
void input_su(int num,int *p);
int check_su(int num,int *o,int *p);
void add_list(int *p,int,int,int,int);
void show_list(int num);

void main()
{
 int num,re[MAX],input[MAX],count=1,s;

 printf("********************************\n");
 printf("* !!야구 게임을 시작 합니다 !! *\n");
 printf("********************************\n");

 printf("몇자리 게임을 하겠습니까? ");
 scanf("%d",&num);
 rand_su(num,re);  // 랜덤 수를 입력 합니다.

 while(1)
 {
  printf("\n\n%d 번째 시도 입니다 .  %d  /  %d \n",count,count,COT);
  input_su(num,input);
  s=check_su(num,re,input);

  if(count>=COT)
  {
   printf("\n시도 안에 맞추지 못하였습니다.\n");
   break;
  }
  else if(s==3) printf("\n\n 축하합니다!!  야구 게임을 성공 하였습니다 \n\n");
  count++;
 }
 //  
}
void show_list(int num)
{
 int i,count=0;
 list_p p;
 p=head;
 printf("\n###################################\n");
 printf("         입력 결과  리스트             ");
 printf("\n###################################\n");
 for(;p!=NULL;p=p->next)
 {
  printf("\n\n%d : 번째 입력  결과  \n",++count);
  for(i=0;i<num;i++)
  {
   printf("%d ",p->a[i]);
  }
  printf("Strink :  %d  Ball  : %d  Out %d \n",p->s,p->b,p->o);
 
 }
}

int check_su(int num,int *q,int *p)
{
 int i,j,out,s=0,o=0,b=0;
 for(i=0;i<num;i++)
 {
  for(j=0;j<num;j++)
  {
   
      if(*(q+i) == *(p+i))
   {
    s++;
    j=num;
   }
   else if(*(q+i) == *(p+j))
   {
    b++;
    j=num;
   }
   else
   {
    out++;
   }
  }

  if(out==num)
  {
   o++;
  }
 }

    add_list(p,s,b,o,num);  // 링크드 리스트에 항목을 추가

 printf("\n\n입력 값  :");
 for(i=0;i<num;i++)
 {
  printf("  %d  ",*(p+i));
 }

 printf("\nStrink : %d   Ball : %d   Out  : %d \n",s,b,o);

  return s;

}

void add_list(int *pt,int s,int b,int o,int num)
{
 int i=0;
 list_p p,temp;
 p=head;
 temp=(list_p)malloc(sizeof(struct list));

 for(i=0;i<num;i++)
 {
  temp->a[i]=*(pt+i);  
 }

 temp->s=s;
 temp->b=b;
 temp->o=o;
 temp->next=NULL;

 if(p==NULL)
 {
  head=temp;  
 }
 else
 {
  for(;p->next!=NULL;p=p->next);
  p->next=temp;
 }
}

void input_su(int num,int *p)
{
 int i,a;
 for(i=0;i<num;i++)
 {
  printf("\n%d 번째 값을 입력 하세요 ? ( -1 를 입력 하면 입력 했던 리스트를 보여줍니다)",i+1);
  scanf("%d",&a);
 
  if(a==-1)
  {
   show_list(num);
   i--;
  }
  else if(a>10 || a<0)
  {
   printf("\n값은 0과 9사이 값만 입력 하실 수 있습니다.\n");
   i--;
  }
  else *(p+i)=a;
 }

}

void rand_su(int num,int *p)  // 랜덤 수를 입력 합니다.
{
 int i;
 printf("랜덤한 수를 입력합니다.");
 srand(time(NULL));
 for(i=0;i<num;i++)
 {
  *(p+i)=rand()%10;
  //printf("\n %d",*(p+i));
 }
}


 


질문은 알아서 ....
posted by 꿈을드림
2009. 3. 16. 12:41 Algorithm

C언어에 대한 나름 생각을 정리해 본다.
포인터는 Address ...  실제로 직접적으로 사용하기 보다 간접적으로 잣대기를 이용해서
사용하기 위한다고 생각하면된다.

일반 C언어에서
다음과 같이 "  int a  " 라고 선언하였을 경우
컴퓨터는 임시적으로 정수형 값을 넣을 수 있는 메모리 공간을 할당하여  그곳의 이름을 a라고 한다. 그래서 " a=10 " 라 선언하면 그 메모리 공간에 값을 10이라고 설정하게 된다.

포인터에 대한 간단한 예제를 보자

#include <stdio.h>
void main(void)
{
 int a=1,b=2;
 int *p=a,*p2=&b;
    printf("int sizof : %d ",sizeof(int));
    printf("a address : %d \n",&a);
    printf("b address : %d \n",&b);
    printf("p address : %d \n",&p);
    printf("p point : %d \n",p);
    printf("p point : %d \n",*p2);
}

결과는

int sizof : 4 a address : 1245052
b address : 1245048
p address : 1245044
p point : 1
p point : 2

다음과 같이 나온다 .
int 형 크기는 4byte이며 a라는 정수형 변수가 할당된 메모리는 1245052 16진수표기가 아니라 10진수라 이렇게 나온다. 16진수로 보려면 %x 로 보면 된다.
b 라는 정수형 변수는 1245048  a변수와 b의 변수 사이는 int 형의 크기 4byte 차이가 나는 걸 볼수 있다.

int *p <- 포인터 변수 선언부분이다..  위에 보면 int *p=a 선언과 정의 를 같이 했다.

여기서 선언이란..  컴퓨터에게 이러한 변수를 쓰겠다고 얘기하는 것이고
          정의는   컴퓨터에게 다음의 변수의 값을 이렇게 쓰겠다고 얘기하는 것이다.

int *p = a;   포인터형

-----------------------------------------------------------------------------------
posted by 꿈을드림
2009. 3. 13. 01:22 이런 저런일들
수업도우미..

유비쿼터스로 인한.. 학생 관리 시스템.. -_-;; 어디서 많이 생각 나지 않는가??

누군가 멘토 주제를 정할때.. 고민할때 나왔던.. 시스템이다..

@_@ 자세한것은 스샷과 함께.....
posted by 꿈을드림
2009. 3. 11. 00:45

사용자 삽입 이미지

도서관 개인 열람실을 이리저리 수소문 해서 하나 빌렸다..
ㅎㅎ
그래서 공부할 거리 이것 저것 챙겨서 오후 2시쯤에 도서관으로 숑!!!
거진 1년 반만의 도서관이였다.. 후아..사람많더라.. 이제 개강 일주일 지났을 뿐이였는데..  

벌써 신입생들은 적응하고 공부하는 건가...

 99년 일학년 도서관은 6층인가.. 잡지 코너가 있는데.. 그곳에 가서 컴퓨터 잡지나 보거나.. 4층에서 소설책이나 만화책으로.. 시간을 때우곤 했는데... 휴우~~  요새에들은 아닌가.... 지금은 2009년 ㅡ.,ㅡ 아~~ 10년 ㅅㅂ~~

첨으로 가본 개인 열람실.... 오우... 좋네... 스텐드도 있고. 아늑한 공간... ㅋㅋ 근데 이런.. 위에 보니..뻥 뚫렸네... 일명 화장실 처럼 되어있다고 생각하면 된다 ...... ㅋ  왜이렇게 해놨지 ㅋㅋ !!

아무튼 이리저리 펴놓고 공부할려고 했는데... 이런 바보가 있는지..필기구를 안들고 왔다는... 아놔.... -_-;; 멀뚱 멀뚱 봐서 난 공부가 안되서.. 10분만에 나와버렸다.

또 5층에서 이런저런 이야기 나누다가... ㅋㅋ!!! 결국 3시에 ...공부하러.. 이리저리 졸다가 공부하다가.. ㅋㅋ 옷을 얇게 입고 가서 그런지... 춥더라.........ㅠ0ㅠ...그래서 5시에 와버렸지..............  

근데 개인열람실에서 귓에 이어폰 꼽고 공부하니까 공부좀 되던데.. 앞으로 계속 이용해야겠다.

 드디어 해야지 해야지 하던걸 조금이라도 시작해서 다행이라는 생각이 든다.. 앞으로 열심히 ^^ 아자!!!


posted by 꿈을드림
2009. 3. 7. 00:51 English Study


이리저리 영어듣기를 찾다가.. CNNez로 해보기로 했음... 말은 왤케 빠른지...  잘 들리지도 않음.... 아무튼 스크립트 1.

혹시 CNNez로 공부 해보겠다는 사람은 ... 글을 남겨주세요.


       1.  
South Korea Unveils $10.8 Billion Stimulus Plan for 2009

A faltering national currency and the slowest economic growth in four years, these worrying factors are fueling fears over the state of South Korea's economy.

Monday, Seoul unveiled a stimulus plan for 2009, including tax cuts and new government spending worth about $ 11 billion.

One of the goals is to throw small business owners a lifeline

Sohn Jie-Ae has more on how they're coping in these hard times.

These days, Ou doesn't need a cup of Joe to keep him up at night.

All he has to do is (to) think of how to keep his once fast-growing chain of organic coffee shops profitable.

Ou's customers sip their coffee for the same price they did in May, but Ou's cost of importing freshly roasted coffee beans have jumped at least 20% due to the exchange rate alone.

Yeah, I think the intensity of the knot in the stomach has increased somewhat in the last year.

Ou knew trouble was brewing when oil prices skyrocketed at the beginning of the year.

When the Korean won plummeted against the U.S. dollar, he knew he had to drastically cut costs in order to survive.

He's already found a local producer for his previously U.S. made paper cups, and now he's looking to roast his coffee beans in Korea.

Ou's coffee shop dilemma is just a microscopic example of why Korean companies across the board have been hit harder than those in most other countries; the stock market losing over 40% of its value since the beginning of the year.

The U.S. dollars gains against the Korean won started earlier this year; then skyrocketed when the global financial crisis hit and everyone was scrambling for dollars, raising fears about Korean banks falling victims.

Some point the finger at poor judgement by a new government that wanted to stimulate exports by weakening the Korean won and making Korean products cheaper abroad then couldn't control the freefall.

From the time that this situation spread all over the world globally, the Korean economic team responded lately, inappropriately, inconsistently and sometime against the market, with a wrong belief that they can control the market.

From the President on down, government officials assured the domestic and international markets

that with foreign currency reserves of some $240 billion; Korea was strong enough to ride out the crisis.

The Korean government will pour sufficient and pre-emptive cash into the market until the uncertainty is overcome.

And it was only when the government announced the $30 billion currency swap line with the U.S. Federal Reserve in late October that the market seemed to calm down and fears eased.

Nevertheless, the market has been hit hard and the government is introducing measures to stimulate domestic demand.

But entrepreneurs like Ou can't wait.

We can't sit around.

Before it was... in the beginning it was panic, I think, within consumers and even our staff,

but now I think it's more of a crisis where we see that something we have to work our way through.

Luckily, Ou said, he hasn't seen sales drop.

He says while Koreans may not shop, they still need their cup of Joe.

Sohn Jie-Ae, CNN, Seoul.


해석은 알아서 해보길...
아마 이거가지고 일주일 버티는지 모르겠지만.. 단어는 30프로 들리긴 하는데..

내용이 뭐라하는지 ... 아직은...

posted by 꿈을드림
2008. 11. 20. 20:07 Algorithm

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

#define MAX_VERTICES 10
#define MAX_QUEUE_SIZE 100
#define IS_EMPTY(ptr) (!(ptr))
#define IS_FULL(ptr) (!(ptr))

void bfs(int);

typedef struct edge *edge_pointer;

typedef struct edge{
  short int marked;
  int vertex1;
  int vertex2;
  edge_pointer path1;
  edge_pointer path2;
};

edge_pointer graph[MAX_VERTICES];

int visited[MAX_VERTICES];

typedef struct queue *queue_pointer;

typedef struct queue
{
  int vertex;
  queue_pointer link;
};

void addq(queue_pointer *,queue_pointer *,int);
int deleteq(queue_pointer *);

void addq(queue_pointer *front,queue_pointer *rear,int vertex)
{
 queue_pointer temp =(queue_pointer)malloc(sizeof(struct queue));
 if(IS_FULL(temp))
 {
  fprintf(stderr,"The memory is full\n");
  exit(1);
 }

 temp->vertex = vertex;
 temp->link = NULL;
 if(*front) (*rear)->link = temp;
 else *front = temp;
 *rear = temp;
}

int deleteq(queue_pointer *front)
{
  queue_pointer temp=(*front);
  int temp2=0;
  
  temp2=(*front)->vertex;
  *front=temp->link;
  free(temp);
  return (temp2);

}

void main()
{
 int i=0;
 struct edge edges[10];
 edges[0].vertex1=0;
 edges[0].vertex2=1;
 edges[0].path1=&edges[1];
 edges[0].path2=&edges[2];

 edges[1].vertex1=0;
 edges[1].vertex2=2;
 edges[1].path1=NULL;
 edges[1].path2=&edges[4];

 edges[2].vertex1=1;
 edges[2].vertex2=3;
 edges[2].path1=&edges[3];
 edges[2].path2=&edges[6];

 edges[3].vertex1=1;
 edges[3].vertex2=4;
 edges[3].path1=NULL;
 edges[3].path2=&edges[7];

 edges[4].vertex1=2;
 edges[4].vertex2=5;
 edges[4].path1=&edges[5];
 edges[4].path2=&edges[8];

 edges[5].vertex1=2;
 edges[5].vertex2=6;
 edges[5].path1=NULL;
 edges[5].path2=&edges[9];

 edges[6].vertex1=3;
 edges[6].vertex2=7;
 edges[6].path1=NULL;
 edges[6].path2=&edges[7];
 
 edges[7].vertex1=4;
 edges[7].vertex2=7;
 edges[7].path1=NULL;
 edges[7].path2=&edges[8];

 edges[8].vertex1=5;
 edges[8].vertex2=7;
 edges[8].path1=NULL;
 edges[8].path2=&edges[9];

 edges[9].vertex1=6;
 edges[9].vertex2=7;
 edges[9].path1=NULL;
 edges[9].path2=NULL;

 graph[0]=&edges[0];
 graph[1]=&edges[0];
 graph[2]=&edges[1];
 graph[3]=&edges[2];
 graph[4]=&edges[3];
 graph[5]=&edges[4];
 graph[6]=&edges[5];
 graph[7]=&edges[6];
 
/*
 struct edge edges[3];
 edges[0].vertex1=0;
 edges[0].vertex2=1;
 edges[0].path1=&edges[1];
 edges[0].path2=NULL;
 
 edges[1].vertex1=0;
 edges[1].vertex2=2;
 edges[1].path1=NULL;
 edges[1].path2=&edges[2];

 edges[2].vertex1=2;
 edges[2].vertex2=3;
 edges[2].path1=NULL;
 edges[2].path2=NULL;

 graph[0]=&edges[0];
 graph[1]=&edges[0];
 graph[2]=&edges[1];
 graph[3]=&edges[2];

 printf("%d ",&edges[0]);
 printf("%d ",&edges[1]);
 printf("%d ",&edges[2]);
 printf("\n%d ",edges[0].path1);
 printf("\n%d ",edges[1].path1);
 printf("\n\n\n");
 bfs(2);
*/

 bfs(0);
}


void bfs(int v)

 edge_pointer w;
 queue_pointer front,rear;
 front=rear=NULL;  // Quere의 초기화
 visited[v] = 1;  // BFS처음 값을 방문했다고 체크
 addq(&front,&rear,v);  // BFS처음값을 queue에 넣는다.

 while(front)  // queue의 값이 NULL일 때까지 반복한다.
 {
  v = deleteq(&front); //우선 queue 하나를 삭제한후 값을 가지고 온다.
  printf("%d ->",v);
  w=graph[v];
  // multi list는 vertex 1 vertex2 어느 값이 선택될지 몰라, 두 경우를 나누어 설정
  // 하나의 노드가 설정 되면 인접한 노드가 등록 된지 체크후 없으면 체크한한후 큐에 등록
  // 그 노드가 Null이 될때까지 이동하면서 반복 하는게 주 내용.
  while(w)
  {
   if(v==w->vertex1)
   {  
    if(!visited[w->vertex2])
    { 
     visited[w->vertex2] =1;    
     addq(&front,&rear,w->vertex2);
    }
    w=w->path1;
   }

   else if(v==w->vertex2)
   {
    if(!visited[w->vertex1])
    { 
     visited[w->vertex1] =1;
     addq(&front,&rear,w->vertex1);
    }
    w=w->path2;
   }
  } 
 }
}


posted by 꿈을드림
2008. 11. 20. 20:02 카테고리 없음

LINUX IOCTL (For IGMP)

 

 

IOCTL ( Input / Output Control의 약자)

리눅스의 입출력을 제어하기 위한 시스템 콜.

파일 디스크립터(filedescripteor)를 가지고

캐릭터 디바이스(Character Device)를 조종하는데 사용된다.

        어느 특정한 Device를 의미.

 

그럼 여기서 시스템 콜이란 무엇인가?

 

커널에서 직접 제공하는 서비스를 말함.

 

<커널: 실제로 행동하는 핵심>

Shell은 커널을 감싸고 있는 껍데기 Shell이 커널을 감싸고 있기 때문에 직접적인 커널 명령이 아니라 Shell 명령을 통해서 커널에게 명령을 줄 수 있다.

 

시스템 콜 테이블은 "arch/i386/kernel/entry.S" 리눅스 커널 소스파일에 정의.

 

우선 파일 디스크립터?

        시스템으로부터 할당 받은 파일이나 소켓을 대표하는 정수를 의미

           시스템이 만들어 놓은 것을 가리키기 좋게 하기 위해 시스템이 우리들에게 건데주는 숫

           에 불과하다. (핸들 이라는 표현도 함께 사용)

          

 

IOCTL 매개변수 전달과정

ioctl()  인자는  커널  내부처리를  거쳐서  디바이스의 ioctl   전달 
ioctl() -> sys_ioctl() -> device ioctl()
, ioctl   시스템  콜의  일종

..
..
..
posted by 꿈을드림
2008. 11. 20. 13:31 카테고리 없음

구매하고 싶은 넥타이 슬림형이닷..

MtoM에서 파는군  가격은 16,000원 ....

링크 주소
http://m2m.ne.kr/front/php/product.php?product_no=1358&main_cate_no=25&display_group=1

posted by 꿈을드림