일이 코딩 시험인데ㅠㅠㅠ
연결리스트도 못만드는 븅신이라 살려주셈ㅠㅠㅠㅠ
자꾸 이런 에러가 뜨는데 왜 동적할당도 안될까???
#include <stdio.h>
#include <stdlib.h>
#define Element char
#define bool unsigned char
#define true 1
#define false 0
typedef struct list_node *list_pointer;
typedef struct list_node {
Element data;
struct list_node *link;
}list_node;
list_pointer p;
void list_insert(list_pointer head, Element e){
p = (list_pointer*)malloc(sizeof(list_node));
p -> >
p -> link = NULL;
head -> link = p;
}
void list_delete(list_pointer head, Element e){
int node=0, next=0;
if(head == NULL){
printf("list is empty");
}
else{
while(p->link = NULL){
if(p-> e {
node = &p;
next = p->link;
}
p = p->link;
}
p = head;
while(p->link){
if(p->link == node){
p->link = next;
}
p = p->link;
}
free(&node);
}
}
list_pointer list_search(list_pointer head, Element e){
int adrs=0;
tmp = head;
while(tmp == NULL){
if(tmp -> e {
printf("node address: %p\ndata : %c\nlink : %s\n", tmp, tmp->data,tmp->link );
}
else{
printf("%c is not in the list!!!", e);
}
tmp = tmp -> link;
}
}
bool list_empty(list_pointer head){
}
void list_show(list_pointer head){
if(head == NULL){
printf("List is empty!!!\n");
}
else{
p = head;
while( p-> link = NULL){
printf("%c ", p->data);
p = p -> link;
}
}
}
void main()
{
char c, e;
list_pointer head, tmp;
list_pointer p;
printf("*********** Command ***********\n");
printf("+<c>: Insert c, -<c>: Delete c\n");
printf("?<c>: Search c, S: Show, Q: Quit\n");
printf("********************************\n");
// dummy head 노드
head = (list_pointer*)malloc(sizeof(list_node));
head-> ';
head->link = ' ';
while (1) {
printf("\nCommand> ");
c = getchar();
putch(c);
c = toupper(c);
switch (c) {
case '+' :
e = getchar();
list_insert(head, e); break;
case '-' :
e = getchar();
list_delete(head, e); break;
case '?' :
e = getchar();
p = list_search(head, e);
break;
case 'S' :
list_show(head); break;
case 'Q' :
printf("\n");
exit(1);
default : break;
}
}
}
경고 #1. list_pointer가 list_node * 이기 때문에 malloc 함수의 반환 값을 list_pointer *로 캐스팅하는 게 아니라 list_node *로 캐스팅하든지 list_pointer로 캐스팅해야 경고가 사라짐.
list_delete 함수의 node, next 변수는 list_pointer 또는 list_node * 형이어야 함.
등등 문제 투성이구만.
자료구조 시험 칠때 저흰 연결리스트 손코딩을 시켰죠 그래서 소스 코드를 다 외웠습니다.
외우니깐 적용되고 금방할 수있어요. 닥 외우셈