728x90

Application/C++ 4

[C++] enum 중복 값 쓰기

아래와 같이 코드를 작성하면 다른 enum의 변수값인데도 같은 변수명이라는 이유로 컴파일에서 에러를 발생시킨다 #include enum Index { _111, _222, _333, _444, MAX }; enum Index1 { _111, _222, _333, _444, MAX }; int main(int argc, char **argv) { return 0; } 이런 에러를 우회하는 방법으로는 namespace를 쓰는 방법이 있다 #include namespace Type_A { enum Index { _111, _222, _333, _444, MAX }; } namespace Type_B { enum Index { _111, _222, _333, _444, MAX }; } int main(int a..

Application/C++ 2022.12.22

[C++] 정렬 되는 연결 리스트(링크드 리스트) 만들기

학번과 성적을 입력받으면 학번에 따라서 자동 정렬되는 연결 리스트 (링크드 리스트) 예제 코드 #include #include #include #define LEN sizeof(struct Student) struct Student { int num; float score; struct Student *next; }; int n = 0; void print(struct Student * head); struct Student * insert(struct Student * head, struct Student * stud) { if(head == NULL) { head = stud; } else { struct Student *temp; if(head->num > stud->num) { temp = hea..

Application/C++ 2022.12.15
728x90
반응형