단일 연결 리스트 질문입니다..
난길
질문 제목 : 단일 연결 리스크 구현입니다.코드는 간단히 1: 입력 2: 삭제 3: 출력 4 : 종료입니다.
지금 1입력부분때문에 pdata nodealloc(int data)
pdata makenode(pdata head,int todata)
void inputnode(pdata *head,int data)
3개의 함수를 사용중인대 1개로 줄일라면 어떻게 해야하나요??줄이면 계속 주소참조로 에로발생합니다.질문 내용 : #include stdafx.h
#include string.h
#include stdlib.h
typedef struct _node {
int input;
struct _node *link;
}data,*pdata; //구조체 선언
void remove(pdata *head)
{
pdata p=*head;
pdata pre;
int deletecount;
printf(지우고자 하는 수는 ? : );
scanf_s(%d,&deletecount);
while(p && p-input != deletecount)
{
pre = p;
p=p-link;
}
if(p-link == null)
printf(찾는 data 없다 \n);
else if(*head == p)
{
*head = p-link;
free(p);
}
else
{
pre-link = p-link;
free(p);
}
}pdata nodealloc(int data)
{
pdata p = (pdata)malloc(sizeof(data));
p-input = data;
p-link = null;
return p;
}
pdata makenode(pdata head,int todata)
{
pdata n,p;
p=head;
n=nodealloc(todata);
/*n=(pdata)malloc(sizeof(data));
n-input = todata;
n-link = null;*/
if(head==null)
return n;
while(p-link)
p=p-link;
p-link = n;
return head;
}
void inputnode(pdata *head,int data)
{
*head=makenode(*head,data);
}
void printnode(pdata head)
{
pdata p=head;
int i;
printf(\n\n);
for(i=1;p;p=p-link,i++)
{
printf(%d 번째 요소 %d\n,i,p-input);
}
printf(\n\n);
}
int _tmain(int argc, _tchar* argv[])
{
int inputcount=0;
int count=0;
pdata head=null;
while(1)
{
printf(1. 정수입력 :\n);
printf(2. 정수 삭제 :\n);
printf(3. 정수 출력 :\n);
printf(4.종료 );
scanf_s(%d,&inputcount);
switch(inputcount)
{
case 1:
printf(정수 입력 : );
scanf_s(%d,&count);
inputnode(&head,count);
break;
case 2:
remove(&head);
break;
case 3:
printnode(head);
break;
case 4:
printf(종료합니다 \n);
break;
}
if(inputcount == 4)
break;
}
return 0;
}
-
앨런 2023-10-08
예 비쥬얼 2008인대 저렇게 나오더라고요 //
-
말근 2023-10-08
_tmain이라고 적어도 에러 안뜨나요??
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |