오름차순으로 삽입되게끔 수정좀 부탁드려여 ㅠ
리라
질문 제목 :
오른차순으로 삽입되게끔 수정좀 해주세영 ㅠ
오름차순으로 삽입이안되서 그러는데 더이상 잘 모르겟네영 ㅠ
수정좀 해주시거나 설명도 + 해주시면 더욱더 감사합니다 ㅠ질문 내용 :
#include stdio.h
#include stdlib.h
#include string.h
#define success 1
#define fail 0
//=====================================================
//typedef
//=====================================================
typedef struct __node{
int num;
struct __node *nextp;
}_node;
//======================================================
//global variable
//=======================================================
#define size 10
_node *freelistp;
_node *headptr;
_node node[size];
//
int i_init_freebuf()
{
int i = 0;
headptr = null;
//
for (i=0; i=size; i++)
{
node[i].num = 0;
if(i+1 != size)
node[i].nextp = &node[i+1];
}
node[i].nextp = null;
freelistp = &node[0];
return success;
}
//
int dsp_list(_node *headptr)
{
if( headptr ==null)
{
printf([ dsp_list ] empty !!\n);
return fail;
}
printf([ dsp_list ] the list contains :);
while( headptr )
{
printf( [%d], headptr-num);
headptr = headptr-nextp;
}
printf(\n);
return success;
}
//
_node* get_free_node()
{
_node* freenode = null;
if( !freelistp )
{
printf([ get_free_node() ] freebuffer empty !!\n);
return null;
}
freenode = freelistp;
freelistp = freenode-nextp;
printf([ get_free_node() ] get freebuffer - success!!\n);
return freenode;
}
//
_node* put_free_node(_node *freenode)
{
printf(node : [%d], freenode-num);
_node *ptr;
if( freenode == null)
{
printf([ put_free_node() ] parameter is null !!\n);
return null;
}
ptr =freelistp;
freelistp = freenode;
freenode-nextp = ptr;
printf([ put_free_node() ] free freebuffer - success!!\n);
return freenode;
}
//
int insert_node(int num)
{
_node *newptr;
_node *temp;
if(headptr == null){
headptr = (__node *) malloc(sizeof(__node));
headptr-num = num;
headptr-nextp = null;
}
else{
temp = headptr;
while(temp-nextp != null)
{
temp = temp-nextp;
}
newptr = (__node *) malloc(sizeof(__node));
newptr-num = num;
temp-nextp = newptr;
newptr-nextp = null;
}
get_free_node();
return success;
}
//
int delete_node(int num)
{
_node *temp;
_node *deltemp;
temp = headptr;
if (headptr-nextp == null){
headptr=null;
put_free_node(temp);
return success;
}
else if(headptr-num == num)
{
headptr = temp-nextp;
put_free_node(temp);
return success;
}
else{
while(1)
{
if(temp-nextp-num == num){
deltemp = temp-nextp;
break;
}
else{
temp=temp-nextp;
}
}
temp-nextp = deltemp-nextp;
put_free_node(deltemp);
return success;
}
}
int main()
{
int selmenu;
int retvalue;
char data[10];
i_init_freebuf();
printf( freelist = \n);
dsp_list(freelistp);
for (; ; )
{
//메뉴선택
printf( select \n);
printf(\t1 : insert 2 : delete 3 : exit\n\t);
retvalue = scanf(%d, &selmenu);
if(retvalue == eof || retvalue ==0 || selmenu 0 || selmenu 3)
{
printf(\t invalid selection. retry \n);
continue;
}
fflush(stdin);
switch (selmenu)
{
case 1:
printf(\tinput a value :);
retvalue = scanf(%s, data);
while(retvalue == 0 || strcmp(data, ) ==0 || strcmp(data, \n) == 0)
{
printf(\t invalid valid value. retry.);
retvalue = scanf(%s, data);
}
if (insert_node(atoi(data)) == success)
{
printf([ insert_node ] success - [%d]!!\n, atoi(data));
printf(\t freelist );
dsp_list(freelistp);
printf(\t linkedlist );
dsp_list(headptr);
}
else
{
printf([ insert_node ]fail - [%d]!!\n, atoi(data));
}
break;
case 2:
printf(\tinput a value :);
retvalue = scanf(%s, data);
while(retvalue == 0 || strcmp(data, ) ==0 || strcmp(data, \n) == 0)
{
printf(\t invalid value. retry.);
retvalue =scanf(%s, data);
}
if (delete_node(atoi(data)) == success)
{
printf([ delete_node ] success - [%d]!!\n, atoi(data));
printf(\t freelist );
dsp_list(freelistp);
printf(\t linkedlist );
dsp_list(headptr);
}
else
{
printf(deletion failed.[%d]\n, atoi(data));
}
break;
case 3:
//프로그램 끝냄
printf(exit.!!\n);
exit(0);
}
}
return success;
}
?xml:namespace prefix = v ns = urn:schemas-microsoft-com:vml /?xml:namespace prefix = o ns = urn:schemas-microsoft-com:office:office /?xml:namespace prefix = w ns = urn:schemas-microsoft-com:office:word /
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2699386 | 구조체 안에 일부분만 char 배열에 복사하려면 어떻게 해야하나요? (1) | 미즈 | 2025-06-25 |
2699361 | 연결리스트 정렬하는 부분에 대해서 질문 드립니다 | 아이처럼 | 2025-06-25 |
2699304 | [기초]아직 안주무시는분 계신가요..?포인터배열? 좀 도와주세요. | 놀리기 | 2025-06-24 |
2699272 | printf() 함수이용해서 프로그램 만들기 질문요! (5) | 다가 | 2025-06-24 |
2699221 | PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? | 파라미 | 2025-06-24 |
2699192 | 설치오류가 자꾸 나요 한번봐주세여~ (1) | 소녀틳향기 | 2025-06-23 |
2699161 | for loop안에 있는 if문 (9) | Orange | 2025-06-23 |
2699105 | 링크더리스트 이전 링크값 출력함수. | 꼬꼬마 | 2025-06-23 |
2699078 | 정수를 한자리씩 배열에 담는 법은 어떻게 하나요.. (4) | 귀염포텐 | 2025-06-22 |
2699024 | C언어 공부하려는데 도와주세요!!! (2) | 달님 | 2025-06-22 |
2698994 | 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) | 별 | 2025-06-22 |
2698967 | 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) | 샤인 | 2025-06-21 |
2698938 | c언어 메모리질문 (3) | 나래 | 2025-06-21 |
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |