C언어 주석좀달아주세요..
찬바리
대학과제로 이명령어들에대해서 주석들을 다는건데
많이달면많이달수록좋다네요
주석좀부탁드리겠습니다
질문 내용 :
#include stdio.h {/* 기본 입출력 함수가 저장된 헤더파일 */
#include stdlib.h
#include string.h
1
typedef struct listNode {
char data[5];
struct listNode* link;
} listNode;
typedef struct {
listNode* head;
} linkedList_h;
linkedList_h* createLinkedList_h(void);
void freeLinkedList_h (linkedList_h*);
void addLastNode (linkedList_h*, char*);
void reverse (linkedList_h*, char*);
void deleteLastNode (linkedList_h*);
void printList (linkedList_h*);
linkedList_h * createLinkedList_h(void) { /*공백 리스트를 만듦 */
linkedList_h* L;
L = (linkedList_h *)malloc(sizeof(linkedList_h));
L-head = NULL;
return L;
}
void addLastNode (linkedList_h* L, char* x) { /* 알고리즘 3.2의 구현 */
listNode* newNode;
listNode* p;
newNode = (listNode *)malloc(sizeof(listNode));
strcpy(newNode-data, x);
newNode-link = NULL;
if (L-head == NULL) {
L-head = newNode;
return;
}
p = L-head;
while (p-link != NULL) {
p = p-link;
}
p-link = newNode;
}
void reverse(linkedList_h* L){/* 알고리즘 3.4의 구현 */
listNode*p;
listNode* q;
listNode* r;
p = L-head;
q = NULL;
r = NULL;
while (p != NULL) {
r = q;
q = p;
p =p-link;
q-link = r;
}
L-head = q;
}
void deleteLastNode(linkedList_h* L) {/* 프로그램 3.2 */
listNode* previous;
listNode* current;
if (L-head == NULL) return;
if (L-head-link == NULL) {
free(L-head);
L-head = NULL;
return;
}
else {
previous = L-head;
current = L-head-link;
while (current-link != NULL) {
previous = current;
current = current-link;
}
free(current);
previous-link = NULL;
}
}
void freeLinkedList_h(linkedList_h* L) {
listNode* p;
while(L-head !=NULL) {
p = L-head;
L-head = L-head-link;
free(p);
p = NULL;
}
}
void printList(linkedList_h* L) {/*프로그램 3.3*/
listNode* p;
printf(();
p = L-head;
while (p !=NULL) {
printf(%s, p-data);
p = p-link;
if (p !=NULL) {
printf(,);
}
}
}
int main() {
linkedList_h*L;
L = createLinkedList_h();/*공백 리스트 L= ()를 생성*/
addLastNode(L, Kim);/*리스트 L = (Kim,Lee,Park)을 생성*/
addLastNode(L, Lee);
addLastNode(L, Park);
printList(L);/*(Kim, Lee, Park)을 출력 */
addLastNode(L, Yoo);/*원소 Yoo를 리스트 끝에 첨가*/
printList(L);/*(Kim, Lee, Park, Yoo)를 출력*/
deleteLastNode(L);/*마지막 원소를 삭제 */
printList(L);/*(Kim, Lee, Park)을 출력 */
reverse(L);/*리스트 L을 역순으로 변환 */
printList(L);/*(Park, Lee, Kim)을 출력*/
freeLinkedList_h(L);/*리스트 L을 해제 */
printList(L);/*공백 리스트 ()을 출력 */
return 0;
}
-
찬솔
C++ Q&A 게시판에 있는 같은 내용의 글은 삭제했습니다.
같은 내용의 글을 여러 게시판에 올리면 도배로 간주되어서 탈퇴될 수 있습니다. 참고하세요.