Coder Social home page Coder Social logo

42-algorithm's People

Contributors

365kim avatar dev-jko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

42-algorithm's Issues

안녕하세요! 질문이 있습니다.

42서울에서 공부하고 있는 taelee라고 합니다.
올려주신 자료로 자료구조를 공부하고 있습니다.
너무 좋은 자료 올려주셔서 감사드립니다!!

현재 stack을 공부하고 있습니다.
array로 구현한 stack에서 stack_clear함수에 대해 질문이 있습니다.
메인문을 살펴보니 stack_clear의 두번째 인자(함수포인터)로 free를 넘겨주는거 같은데요
그러면 굳이 함수를 인자로 받을 필요가 있는지 궁금합니다.
인자로 받지 않고 그냥 내부에서 free로 구현하면 안되나 싶어서요.
free이외의 다른 함수 포인터가 들어오는 경우가 있어서 그런가요?

다시한번 자료구조를 실습해 볼수 있게 올려주신점 감사드립니다!!
공부하는데 큰 도움이 되네요

(circle_linked_list) list_add에 대한 질문이 있습니다.

  1. list_add(t_linked_list *list, void *data, int n)에서 n = 0 일때, list_add의 return 값에 대해서 질문이 있습니다.
    list_add 의 return은 "생성된 요소의 인덱스를 반환 합니다. (0 혹은 양수)" 라고 되어있습니다.
    test.c

    // test.c file의 83line
    for (int i = 0; i < 5; ++i) {
        printf("list_add return value = %d, list_size = %d\n",
    				list_add(list, strdup(test_data[index++]), 0), list_size(list));
        print_list(list);
    	}

    이 부분에서 list_add( , , 0)의 명령은 index가 0인 곳에 add를 시키는 것이니깐 reutrn 값이 0이 되어야한다고 생각 해서 코드를 짯으나,
    nadaram님의 implementation.c에 의하면 n=0 일때는 return : list_size(list) -1을 return 합니다.
    다시말하면, list->head 접근, 계속 ->next로 한바퀴를 돌기 마지막에 생성시킨 양수값을 return합니다.
    이유가 있을까요? 그냥 관점의 차이이겠지만, 궁금해서 질문드립니다
    가볍게 받아주시면 감사하겠습니다!

+제 코드

int ft_add_sub(t_linked_list *list, t_node *add_list, int n)
{
	t_node *prev;
	t_node *next;
	int index_n;

	index_n = n % list_size(list);
	if (index_n >= 0)
	{
		prev = list_get(list, index_n-1);
		next = prev->next;
		prev->next = add_list;
		add_list->prev = prev;
		next->prev = add_list;
		add_list->next = next;
		if (index_n == 0)
			return(list_size(list) - 1); //그래서 이 부분을 추가했습니다.
		return (index_n);
	}
	next = list_get(list, index_n + 1);
	prev = next->prev;
	next->prev = add_list;
	add_list->next = next;
	prev->next = add_list;
	add_list->prev = prev;
	return (list_size(list) + index_n);
}

int list_add(t_linked_list *list, void *data, int n)
{
	t_node *add_list;

	if (list == NULL || data == NULL)
		return(-1);
	add_list = create_elem(data);
	list->size++;
	if(list_size(list) == 0)
	{
		list->head = add_list;
		add_list->next = add_list;
		add_list->prev = add_list;
		return (0);
	}
	return(ft_add_sub(list, add_list,n));
}

double linked list에서 ex00 구조체에서 오타가 있습니다

typedef struct s_node
{
int data;
struct s_node *prev;
struct s_node *next;
} t_node;

typedef struct s_linked_list
{
unsigned int size;
t_node *head;
t_node *tail;
} t_linekd_list;-> t_linked_list;


번외로 질문이 있는데, 혹시 알고계시다면 답변 부탁드립니다.
t_linked_list * new= malloc(sizeof(t_linked_list));
new = NULL;
free(new);
new가 동적할당된 메모리주소를 가리키지않으니깐 이런식으로 free를 하면, 메모리누수가 나는 것은
주어진 문제를 풀면서 알게되었습니다!

leaks에 대해 조금더 알아보고자 몇가지 장난을 쳐봤는데요.
위 코드처럼 할 경우 grademe.sh 에서 2 leaks를 띄워줍니다.
그리고 new에 NULL 할당하지않고 free(new); 를 해줄 시에 0 leaks 가 됩니다.
제가 궁금한건 왜 1(개)단위씩이 아니라 2 (개)단위씩 메모리누수가 나는 건가요??
넘어갈법한데 nadaram님이 알고계실 수도 있겠다는 생각이 들어서 질문드립니다. 감사합니다

README.md파일 오기

안녕하세요

README.md 파일에서 4358번 생태학이 4258번 생태학으로 잘못 표기되어있습니다
(링크는 4358번으로 잘 연결됩니다!)

항상 감사드립니다 (--)(__)

무방향 그래프 (인접행렬) 질문드립니다!

안녕하세요!
저는 지금 그래프 에서 무방향 그래프를 학습 중인데요 ✏️
예제 구현 중 궁금한 점이 생겨 질문드립니다!

질문1 : graph_traversal 구현 중 순회방법

https://github.com/nadarm/42-algorithm/blob/1ab4dbed3006c0194df6825408460685b292d635/graph/undirected_matrix/implementation/graph.c#L129-L165

순회 중 혹시 143행에서 i 값을 i = 0대신에 i = curr + 1 로 해도 괜찮을까요?
무방향 그래프는 행렬이 대칭이고 순회를 항상 0부터 시작하기 때문에 가능할 것 같은데 뭔가 놓치고 있는게 있을까해서 질문 드립니다.

(그림출처:https://lasthere.tistory.com/15)

질문2 : make_graph을 구현 중 메모리해제

https://github.com/nadarm/42-algorithm/blob/1ab4dbed3006c0194df6825408460685b292d635/graph/undirected_matrix/implementation/graph.c#L111-L127

120행에서와 같이 data[i]는 매개변수로 전달받는 free_data라는 함수로 해제시켜주고 있습니다. (121행에서 matrix[i]가 라이브러리의 free함수로 해제시켜주는 것과 대조됩니다)

https://github.com/nadarm/42-algorithm/blob/1ab4dbed3006c0194df6825408460685b292d635/graph/undirected_matrix/implementation/graph.c#L190-L217

그런데 make_graph을 구현할 때에 프로토타입에는 별다른 매개변수 없고, 그래프 해제 시 213행과 같이 라이브러리의 free함수를 전달하게 됩니다.
그렇다면 free_graph함수에 매개변수로 주어지던 free_data라는 함수는 라이브러리의 free함수와 기능이 같은 것인가? 하는 의문이 들어 질문 드립니다.

감사합니다! 42알고리즘 만세!

System("leaks ....")가 malloc의 메모리 누수를 못 잡기도하나요?

캡처_2020_05_12_20_40_54_240

nadaram님의 tester를 작성하신 implementation.c 로 돌린 결과입니다.
제 생각에는 5개가 발생해야할 것 같은데, 0 leaks 가 나옵니다.
(init()으로 생성한 t_stack =1개, strdup()으로 생성한 data 와 해당 t_node = 4개)
leaks가 못잡는 부분이 있는걸까요?
slack에서 leaks이 아닌, valgrind로 메모리체크하는 것을 보았습니다. leaks 보다는 valgrind가
정확 할까요?

5.tree 중 접두사트리 insert 구현 관련 질문드립니다

nadarm님 안녕하세요
문제 올려주시는 덕분에 감사히 학습하고 있습니다.

5.tree에서 접두사트리 예제 구현에 어려움이 있어 질문드립니다.

테스트 결과를 보면 insert함수가 문제인 것 같습니다.

nadarm님의 테스트 메인문에서 str하나 insert할때마다 trie가 출력되도록 해주셨는데
저의 경우 테스트 결과에서 첫번째 str인 "abc"부터 나오지 않습니다.

insert이전에 필요한 create_node함수나 init함수에 문제있수도 있어 여러번 봤지만 아무래도 insert함수가 문제일 것 같습니다.

아래는 제 insert 코드입니다. "abc"가 새로 들어간다고 가정했을 떄 따라가보면 잘 들어갈 것 같고, nadarm님의 코드와도 기능이 비슷하게 짜인 것 같은데 출력이 전혀 안되는 답답한 상황입니다... 코드 한 번 봐주시면 정말 감사하겠습니다..!

#include "trie.h"

bool trie_insert(t_trie *trie, char *str)
{
	t_node	*curr;
	int     i;
	int     j;

	if (trie == NULL || str == NULL || str[0] == '\0')
		return (false);
	j = str[0] - 'a';
	curr = (*trie)[j];
	if (curr == NULL)
		curr = create_elem();
	i = 1;
	while (str[i])
	{
		j = str[i] - 'a';
		curr = curr->next[j];
		if (curr == NULL)
			curr = create_elem();
		i++;
	}
	curr->finish = true;
	return (true);
}

답변 미리 감사드립니다!

(circle_linked_list) 의문점이 있습니다.

  1. list_find
int		list_find(t_linked_list *list, void* data, int (*cmp)(void *data1, void *data2))
{
	t_node		*curr;
	unsigned int	i;

	if (list == 0 || cmp == 0 || (curr = list->head) == 0)
		return (-1);
	i = 0;
	while (i < list->size)
	{
		if (cmp(curr->data, data) == 0)
			return (i);
		i++;
		curr = curr->next;
	}
	return (-1);
}

list_find 함수의 코드입니다.
현재 cmp 함수포인터로 int (*cmp)(void *data1, void *data2)로 표현하였는데,
함수내에서 data1 과 data2의 사용이 없으니, 그냥 int(*cmp)(void *, void *) 로 표현하는게 낫지않나요?
아니면 남겨놓은 이유가 있는 건가요??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.