목록C (86)
W 개발 일지
tildacoderecorder.tistory.com/96 [자료구조] C언어 연결리스트(Linked list) 생성 / 출력 연결리스트 만들기 "월" "화" "수" "목" "금" 등 요일을 데이터값으로 갖는 연결리스트를 만들어보자. typedef struct node { char data; struct node* next; } .. tildacoderecorder.tistory.com 저번 글에서 연결리스트의 생성과 출력에 대한 기본적인 것들에 대해 알아봤다. 이번 글에서는 조건이 있는 출력에 대해 알아볼 것이다. *예제에 쓰인 연결리스트는 전 글의 연결리스트와 동일 마지막에서 두 번째 데이터만 출력하기 마지막에서 두번째만 출력하기 위해서는 먼저 세 가지 조건을 살펴봐야한다. 1. 연결리스트에 다른 노..
연결리스트 만들기 "월" "화" "수" "목" "금" 등 요일을 데이터값으로 갖는 연결리스트를 만들어보자. typedef struct node { char data; struct node* next; } Node; Node* head = NULL; cs 먼저 구조체로 "노드"의 틀을 만든다. 노드에는 데이터가 들어갈 데이터 변수와 다음 노드를 가리킬 포인터 변수가 있어야 한다. 데이터 변수는 어떠한 자료형이어도 상관없다. typedef으로 구조체의 별칭을 Node로 정해둔다. 연결리스트의 맨 앞 노드는 head라 부르며 head는 첫번째 노드를 가리키고 있어야 한다. ( = 첫번째 노드의 주소를 가지고 있어야 함.) 위와 같이 head를 선언한 것을 그림으로 그리면 아래와 같다. head안에 데이터 값도..
포인터에 대한 간단한 요약으로는 다음 사진과 같다. 그림과 같이 포인터는 변수의 메모리 주소'만' 가리키는 화살표와 같다. 이를 이용해서 swap 함수를 만들어보자. 두 수를 a, b에 입력받고 출력한 뒤, 이 두 수를 서로 바꿔주는 swap 함수를 만들어 바뀐 수 또한 출력할 예정이다. 완성 코드는 다음과 같다. #include void swap(int* a, int* b); int main() { int a, b = 0; scanf("%d %d", &a, &b); printf("스왑하기 전 : %d %d\n", a, b); swap(&a, &b); printf("스왑한 후 : %d %d\n", a, b); return 0; } void swap(int* a, int* b) { int tmp =*a; ..
C #include struct info{ char name[20]; int a,b,c; int sum;}; main(){ int n,i,j; scanf("%d",&n); struct info p[n]; struct info tmp; for(i=0;i
C #include typedef struct info{ int height; double weight;}I; main(){ I mom; I dad; I me; scanf("%d%lf",&mom.height,&mom.weight); scanf("%d%lf",&dad.height,&dad.weight); me.height=(mom.height+dad.height)/2+5; me.weight=(mom.weight+dad.weight)/2-4.5; printf("height : %dcm\n",me.height); printf("weight : %.1lfkg",me.weight);}Colored by Color Scriptercs 출처 : www.jungol.co.kr/bbs/board.php?bo_table=..
C #include struct point{ int x; int y; int x2; int y2;}; main(){ struct rectangle{ struct point a; struct point b; }; struct rectangle r; scanf("%d%d%d%d",&r.a.x,&r.a.y,&r.a.x2,&r.a.y2); scanf("%d%d%d%d",&r.b.x,&r.b.y,&r.b.x2,&r.b.y2); int minx,maxx,miny,maxy; minx=r.a.x
C #include #include typedef struct{ char name[50]; char num[50]; char add[50]; }I; main(){ I a[3]; int i,j; char b[50]="zz"; for(i=0;i