데이터 구조 (C 언어 판) 엄 울 민 오 위 민 판 - 추상 데이터 유형의 3 원 조 의 실현
ps: 입 출력 은 스스로 할 수 있 기 때문에 많은 출력 문 구 를 사용 하여 코드 가 지루 해 보이 지만 실제 적 으로 모두 c 의 기초 이 므 로 독자 들 이 인내심 을 가지 고 보 세 요.pps: 블 로 그 를 쓸 때 Markdown 이 약간 멈 추 었 습 니 다. 어떤 원인 으로 인해 코드 사이 에 많은 빈 칸 이 있 는 지 모 르 겠 습 니 다. 실제 코드 길 이 는 211 줄 입 니 다.(본인 코드 스타일 은 산만 형)
#include
", T1[0], T1[1], T1[2]);
    return OK;
}
//         
Status existT(Triplet T) {
    if (T == NULL)
    {
         printf("The Triplet even doesn't exist!What are you doing man?");
         errorcnt++;
         if(errorcnt >= 3)//    ,         
             printf("
Press 8 to create a Triplet dumb ass!( ̄_, ̄ )
");
         return 1;
    }
    else
    {
         return 0;
    }
}
Status InitTriplet(Triplet & T, ElemType v1, ElemType v2, ElemType v3) {
    T = (ElemType*)malloc(3* sizeof(ElemType));//    
    if (!T)return ERROR;
    T[0] = v1;
    T[1] = v2;
    T[2] = v3;
    return OK;
}
Status DestroyTriplet(Triplet & T) {
    free(T);
    T = NULL;
    return OK;
}
Status Get(Triplet T, int i, ElemType & e) {
    if (i < 1|| i>3)return ERROR;
    e = T[i - 1];
    return OK;
}
Status Put(Triplet & T, int i, ElemType e) {
    if (i < 1|| i>3)return ERROR;
    T[i - 1] = e;
    return OK;
}
Status IsAscending(Triplet T) {
    if (T[0] <T[1])
    {
         return T[1] <T[2] ? 1: 0;
    }
    else
         return 0;
}
Status IsDescending(Triplet T) {
    if (T[0] >T[1])
    {
         return T[1] >T[2] ? 1: 0;
    }
    else
         return 0;
}
 
Status Max(Triplet T, ElemType & e) {
    e = T[0] >T[1] ? T[0] : T[1];
    e = e > T[2] ? e : T[2];
    return OK;
}
Status Min(Triplet T, ElemType & e) {
    e = T[0] <T[1] ? T[0] : T[1];
    e = e < T[2] ? e : T[2];
    return OK;
}
int main(void)
{
    Triplet T;
    ElemType e1, e2,e3;
    int com =0,i=0,e=0;
    printf("Please enter the Triplet Element with space:");
    scanf("%d%d%d",&e1, &e2, &e3);
    InitTriplet(T, e1, e2, e3);
    while (com !=-1)//        ,-1     
    {
         //      
         printf("Please choose the action that you want:
");
         printf("1.Destorythe Triplet                         2.Read i th value of the Triplet
");
         printf("3.Change i th value of the Triplet            4.Check the value of the Triplet is ascending or not
");
         printf("5.Findthe max value of Triplet               6.Check the value of the Triplet is descending or not
");
         printf("7.Findthe minimum value of Triplet           8.Create a Triplet
");
         printf("9.Add one Triplet with the original Triplet   -1.Quit
");
         scanf("%d",&com);
         swiztch (com)//            
         {
         case 1:
             DestroyTriplet(T);
             break;
         case 2:
             if(existT(T))
             {
                 break;
             }
             printf("Please enter the order number that you want read:");
             scanf("%d",&i);//               
            if (Get(T, i, e))
            	printf("The %d%s value is %d
", i, i == 1 ? "st" : i == 2 ? "nd" : "rd", e);//                 
      	    else//     i   ,       
    		printf("Tips:Just like its name.It just have 3 elements.");
             errorcnt = 0;
             break;
         case 3:
             if(existT(T))
             {
                 break;
             }
             printf("Please enter the order number that you want change:");
             scanf("%d",&i);//               
             printf("Please enter the value that you want change:");
             scanf("%d",&e);//          
             if (Put(T, i, e)){
    		Get(T, i, e);
   		printf("The %d%s value is %d now
", i, i == 1 ? "st" : i == 2 ? "nd" : "rd", e);
   		errorcnt = 0;
  		}
	     else
   		 printf("Tips:Just like its name.It just have 3 elements.");             
 		break;
         case 4:
             if(existT(T))
             {
                 break;
             }
             if(IsAscending(T))
                 printf("Obviously,it'sascending");
             else
                 printf("Sad~~~it doesn't");
             errorcnt = 0;
             break;
         case 5:
             if(existT(T))
             {
                 break;
             }
             Max(T, e);
             printf("The max value is %d.
", e);
             errorcnt = 0;
             break;
         case 6:
             if(existT(T))
             {
                 break;
             }
             if(IsDescending(T))
                 printf("Obviously,it's descending");
             else
                 printf("Sad~~~it doesn't");
             errorcnt = 0;
             break;
         case 7:
             if(existT(T))
             {
                 break;
             }
             Min(T, e);
             printf("The minimum value is %d.
", e);
             errorcnt = 0;
             break;
         case 8:
             if (T != NULL)//  T    ,     ,       
                 printf("Warning:Youraction will rewrite the Triplet.
");
             printf("Please enter the Triplet Element with space:");
             scanf("%d%d%d", &e1,&e2, &e3);
             InitTriplet(T, e1, e2, e3);
             break;
         case 9:
             if(existT(T))
             {
                 break;
             }
             AddTriplet(T);
             break;
         }   //end of switch
         printf("
");
    }
    return 0;
}
문제 외: 블 루 브리지 컵 성적 이 나 왔 습 니 다. 성 2 를 받 고 하룻밤 을 자 폐 했 습 니 다. (9 개의 문 제 를 썼 습 니 다. 세 개의 빈 칸 을 채 웠 습 니 다. 큰 문 제 는 아직 답 을 맞 추 지 못 했 습 니 다. 마지막 5 분 동안 검사 할 때 BUG 를 찾 았 습 니 다. 경험 을 쌓 은 셈 입 니 다. 앞으로 블 루 브리지 컵 에 참가 하려 면 몇 개의 테스트 데 이 터 를 더 뛰 어야 합 니 다. ACM 이 직접 결 과 를 내 는 것 같 지 않 습 니 다. 233)그러나 자신 이 20 일 동안 여가 시간 에 자줏빛 책 을 따라 목적 없 이 마구 공부 하고 있 을 뿐이다. 학교 에서 도 500 위안 을 보 내 주 었 는데 오히려 명 비 를 받 았 으 니 손해 보지 않 는 셈 이다. 계속 오 리 를 응원 해라!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.