Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

자료구족발보쌈/0708: Difference between revisions

From ZeroWiki
imported>vkdnjdldnjsw
No edit summary
imported>박인서
No edit summary
Line 46: Line 46:
* 연결 리스트
* 연결 리스트


'''수심 Nm. TITLE'''
'''수심 1000m. 스택'''
*  
* 스택 만들기
 
* 문제해결
= 코드 =
= 코드 =
== 예제1 ==
== 예제1 ==

Revision as of 06:47, 8 July 2015

  다시 부활

참여자 명단

함장 장용운 11학번 지각
선원 천준현 15학번 결석
최지혁 출석
박인서 출석
이정재 고향
이원준 출석
조종현 출석
남헌 출석

수업

진행

  1. 장소 : 6층 PC실
  2. 시간 : 14시 30분~

내용

~~기억 속에서 사라진~~ 기존 내용 복습

  • 구조체
  • 동적 메모리 할당
  • 연결 리스트

수심 1000m. 스택

  • 스택 만들기
  • 문제해결

코드

예제1

#include <stdio.h>
#include <malloc.h>

typedef struct _node{
	int value;
	struct _node * next;
} node;

void freeAll(node*);

int main(void) {
	node* head;
	head = (node*)malloc(sizeof(node));

	node* temp = head;
	for (int i = 0; i < 50; i++) {
		temp->next = (node*)malloc(sizeof node);
		temp->value = i;

		temp = temp->next;
	}
	temp->next = NULL;
	temp->value = 50;

	freeAll(head);

	return 0;
}

void freeAll(node* hd) {
	node* t;
	while (hd != NULL) {
		t = hd->next;
		printf("%d ", hd->value);
		free(hd);
		hd = t;
	}
}

숙제

  1. 복습하기
  2. 복습하기
  3. 복습하기


숙제 제출

천준현

최지혁

박인서

  • 연결 리스트
#include <stdio.h>
#include <stdlib.h>

typedef struct node{
	int value;
	struct node * next;
}node;

void freeall(node * hd)
{
	node * t=hd->next;
	while(hd!=NULL)
	{
		t=hd->next;
		printf("%d\n",hd->value);
		free(hd);
		hd=t;
	}
}

int main()
{
	node * head;
	node * temp;
	int i;
	head = (node *)malloc(sizeof(node));
	head->value=0;
	head->next=(node *)malloc(sizeof(node));
	temp=head;
	for(i=0;i<50;i++)
	{
		temp->next=(node *)malloc(sizeof(node));
		temp->value=i;
		temp=temp->next;
	}
	temp->next=NULL;
	temp->value=50;
	freeall(head);
	return 0;
}

이정재

이원준

  • 연결 리스트
typedef struct node{
	int v;
	struct node* next;
}node;

void freeAll(node* hd); //값을 출력하면서 구조체를 free

int fNum(node* hd); //마지막 구조체의 값을 반환

void main(){
	node* head;
	head = (node*)malloc(sizeof(node));

	node* temp = head;

	for (int i = 0; i < 50; i++){
		temp->next = (node*)malloc(sizeof(node));

		temp->v = i;

		temp = temp->next;
	}

	temp->next = NULL;
	temp->v = 50;
	printf("%d\n", fNum(head));
	freeAll(head);
	printf("\n");

}

void freeAll(node* hd){
	node* ntp;
	while (hd != NULL){
		ntp = hd->next;
		printf("%d ", hd->v);
		free(hd);
		hd = ntp;
	}
}

int fNum(node* hd){
	int i;
	node* tp;
	while (hd != NULL){
		i = hd->v;
		hd = hd->next;
	}
	return i;
} 

조종현

남헌



활동지도/2015 자료구족발보쌈