단순 연결 리스트 질문입니다.
별글
질문 제목 : 단순연결 리스트에서 소스가 해결이 안되네요 질문 내용 :
typedef struct node
{
int value;
struct node* next;
}node;
typedef struct list
{
int count;
struct list* head;
}list;
void single_insert(list* new_list, int value, int position)
{
node* new_node;
if(!(new_node = (node*)malloc(sizeof(node))))
fprintf(stderr,%s\n,메모리 할당 실패);
else
memset(new_node,null,sizeof(new_node));
new_node-value = value;
if(position 1 || position-1 new_list-count)
fprintf(stderr,%s\n,범위 초과);
else
{
while(position == new_list-count)
{
new_node=new_node-next;
}
new_node-next = new_list-head;
new_list-head = new_node;
}
new_list-count++;
}
빨간색 친 부분이 에러 부분인데요
new_node는 struct node 이고 new_list는 strcut list입니다.
이 2개의 엔티티에 서로 할당 할 수 없다는 것인데요.
이럴 경우 어떻게 해결 해야 되나요??
-
하예 2023-10-02
감사 합니다. ㅎㅎ 형변환을 생각 못햇네요 .ㅎ
근데 형변환을 쓰지 않고 해결 하려면 어떻게 해야 할지 ;; -
Schokolade 2023-10-02
제가 연결 리스트는 아배웠지만 형변환이니
new_node-next = (struct node*)new_list-head;
\t\t\t\t new_list-head = (struct list*)new_node;
이런식이면 될꺼같은데요 ?