Skip to content

OohelloworldoO/Alogorithm-DataStructure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alogorithm/DataStructure

c/cpp 復健中...

gcc/g++ -o 要生成執行檔名 執行檔名

切換至 cmd compile

Note

科目 實體參考書 OCW
DataStructure 洪逸、王志強 彭文志
Algorithm 林立宇 江蕙如老師

關於指標

struct Student {
    char name[50];
    int score;
    struct Student *next;
};
struct Student* createStudent(char name[], int score) {
    struct Student* newStudent = (struct Student*)malloc(sizeof(struct Student));
    if (newStudent == NULL) {
        printf("Memory allocation failed\n");
        exit(1);
    }
    strcpy(newStudent->name, name);
    newStudent->score = score;
    newStudent->next = NULL;
    return newStudent;
}

我之前對於 *nextstruct Student*有些誤解 最近才搞清楚
白話一點解釋就是struct Student*是指向struct Student這個結構的記憶體位置
*next是指向struct Student結構中下一個位置的指針

(struct Student*)malloc(sizeof(struct Student))malloc 前面是定義 return 大小的資料型態
c 語言 function 前面的是定義資料的型態

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published