연결리스트 소스가 비주얼C에선 잘되고 터보c에선 안됩니다 ㅠ
달달한캔디
질문 제목 : 연결리스트 소스가 어떤컴퓨터에선 잘되고 어떤 컴퓨터에선 안되는데 왜그러는건지좀 알려주세요.. ㅠ질문 요약 :컴퓨터도 다르고 저는 비주얼 6.0 c++으로햇고 교수님 컴퓨터에서는 터보c++ 으로했는데 0입력하면 잘 정지 되는데 교수님 컴퓨터에서는 안되요...질문 내용 :
소스는
#includestdio.h
#includestdlib.htypedef struct listnode{
long data;
struct listnode *link;
}listnode;typedef struct listheader{
listnode *head;
listnode *tail;
int length;
}listheader;void init(listheader *plist)
{ plist-head = plist-tail = null;
plist-length = 0;
}void insert_node(listheader *plist, long data)
{listnode *temp = (listnode *)malloc(sizeof(listnode));
if(temp == null)
exit(1);
temp-data = data;
temp-link = null;
listnode *p;
listnode *q;if (plist-tail == null)
{
plist-head = plist-tail = temp;
(plist-length)++;
}
else
{p = plist-head;while(1)
{
if(temp-data p-data)
{
if(p-link==null)
{
p-link = temp;
temp-link = null;
plist-tail = temp;
(plist-length)++;
break;
}
else
{
q = p;
p = p-link;
}
}
else
{
if(temp-data plist-head-data)
{
temp-link = plist-head;
plist-head = temp;
(plist-length)++;
break;
}
else
{
q-link = temp;
temp-link = p;
(plist-length)++;
break;
}
}
}
}
}
void remove_node(listheader *plist, long lo)
{int i=1;
listnode *re, *lre;
re = plist-head;while(1)
{
if(plist-head-data == lo)
{
plist-head = plist-head-link;
free(re);
(plist-length)--;
break;
}
else
{lre = re;
re = re-link;
i++;}
if(re == null)
{printf(그런 데이터가 존재하지 않습니다.\n);
break;
}
if(re-data == lo)
{
lre-link = re-link;
free(re);
(plist-length)--;
break;
}
else
{
lre = re;
re = re-link;
i++;
}}
}
void reverse_node(listheader *plist)
{
listnode *p, *q, *r;
if(plist-length == 3)
{plist-tail-link = plist-head-link;
plist-head-link = null;
plist-tail-link-link = plist-head;
plist-head = plist-tail;
plist-tail = plist-head-link-link;
}
else if(plist-length == 2)
{plist-head-link = null;
plist-tail-link = plist-head;
plist-head = plist-tail;
plist-tail = plist-head-link;
}
else
{
p = plist-head-link;
q = p-link;
&r = q-link;
p-link = plist-head;
plist-head-link = null;
while(1)
{q-link = p;
p = r-link;
r-link = q;
if(p == null)
{plist-tail = plist-head;
plist-head = r;
break;}
q = p-link;
if(q == null)
{
p-link = r;
plist-tail = plist-head;
plist-head = p;
break;
}
p-link = r;
r = q-link;
if(r == null)
{q-link = p;
plist-tail = plist-head;
plist-head = q;
break;
}
}
}
}
void print_data(listheader *plist)
{
listnode *t;
t = plist-head;
while(t != null)
{
printf(출력 값 : %d\n,t-data);
t = t-link;
}
printf(총 노드 수 : %d\n, plist-length);
}
void main()
{
int con;
long a, d;
listheader list1;
init(&list1);
printf(list1에 들어갈 값을 입력 하세요(0입력시 종료)\n);
while(1)
{
scanf(%d,&a);
if(a==0)
break;
insert_node(&list1, a);
}
while(1)
{printf(옵션 1. 출력 / 2. 뒤집기 / 3. 삭제 / 4. 프로그램 종료 \n);
scanf(%d,&con);
if(con == 1)
{printf(list1출력\n);
print_data(&list1);
}
else if(con == 2)
{reverse_node(&list1);
printf(\nlist1 뒤집기완료\n);}
else if(con == 3)
{printf(\n 삭제할 데이터를 입력하세요\n);
scanf(%d,&d);remove_node(&list1, d);
}
else if(con == 4)
exit(1);
else
printf(그런 옵션 없습니다.);
}
}입니다.왜 그런지좀알려주세요.. ㅠㅠ 제꺼는 0입력하면 잘종료되는데 교수님컴퓨터에서는 안되네요... ㅠㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |