第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

作業(yè)社區(qū)

探索學(xué)習(xí)新天地,共享知識(shí)資源!

0 提交作業(yè)
0個(gè) 布置作業(yè)
0 滿分作業(yè)
得分 100
討論題

浪潮君 的學(xué)生作業(yè):

#include // 引入標(biāo)準(zhǔn)輸入輸出庫(kù),提供 printf 函數(shù) #include // 引入標(biāo)準(zhǔn)庫(kù),提供 malloc、free、exit 等內(nèi)存函數(shù) // 定義鏈表節(jié)點(diǎn)結(jié)構(gòu)體 typedef struct Node { int data; // 數(shù)據(jù)域:存儲(chǔ)節(jié)點(diǎn)的整數(shù)值 struct Node *next; // 指針域:指向下一個(gè)節(jié)點(diǎn)的指針 } Node; // 創(chuàng)建一個(gè)新節(jié)點(diǎn),封裝內(nèi)存分配和初始化過(guò)程 Node *create_node(int value) { Node *new_node = (Node *)malloc(sizeof(Node)); // 分配一個(gè)節(jié)點(diǎn)大小的內(nèi)存 if (!new_node) { perror("內(nèi)存分配失敗"); // 如果分配失敗,輸出錯(cuò)誤信息 exit(EXIT_FAILURE); // 終止程序 } new_node->data = value; // 設(shè)置節(jié)點(diǎn)的數(shù)據(jù) new_node->next = NULL; // 初始時(shí)不指向其他節(jié)點(diǎn) return new_node; // 返回新節(jié)點(diǎn)地址 } // 從大到小順序插入一個(gè)節(jié)點(diǎn)(插入排序式建表) void insert_descending(Node **head, int value) { Node *new_node = create_node(value); // 創(chuàng)建新節(jié)點(diǎn) // 情況 1:鏈表為空,或者新值比頭節(jié)點(diǎn)大 → 插入頭部 if (*head == NULL || value > (*head)->data) { new_node->next = *head; // 新節(jié)點(diǎn)指向原頭節(jié)點(diǎn) *head = new_node; // 更新頭指針為新節(jié)點(diǎn) return; } // 情況 2:在鏈表中找到合適位置插入(保持從大到?。? Node *current = *head; while (current->next != NULL && current->next->data >= value) { current = current->next; // 向后遍歷直到找到插入點(diǎn) } // 插入新節(jié)點(diǎn):new_node 插入在 current 后面 new_node->next = current->next; current->next = new_node; } // 打印整個(gè)鏈表內(nèi)容 void print_list(Node *head) { printf("鏈表內(nèi)容:"); Node *current = head; while (current != NULL) { printf("%d ", current->data); // 打印當(dāng)前節(jié)點(diǎn)的值 current = current->next; // 移動(dòng)到下一個(gè)節(jié)點(diǎn) } printf("\n"); } // 刪除鏈表中所有值等于 target 的節(jié)點(diǎn) void delete_value(Node **head, int target) { Node *current = *head; // 當(dāng)前節(jié)點(diǎn),從頭開(kāi)始 Node *prev = NULL; // 前一個(gè)節(jié)點(diǎn),初始為 NULL while (current != NULL) { if (current->data == target) { // 找到目標(biāo)節(jié)點(diǎn) Node *to_delete = current; // 保存待刪除節(jié)點(diǎn) if (prev == NULL) { // 如果刪除的是頭節(jié)點(diǎn),更新 head 指針 *head = current->next; current = *head; // 當(dāng)前節(jié)點(diǎn)后移到新頭節(jié)點(diǎn) } else { // 刪除的是中間或尾部節(jié)點(diǎn) prev->next = current->next; current = current->next; // 當(dāng)前節(jié)點(diǎn)后移 } free(to_delete); // 釋放刪除的節(jié)點(diǎn)內(nèi)存 } else { // 當(dāng)前不是目標(biāo)節(jié)點(diǎn),向后遍歷 prev = current; current = current->next; } } } // 釋放整個(gè)鏈表占用的內(nèi)存 void free_list(Node *head) { Node *tmp; while (head != NULL) { tmp = head; // 暫存當(dāng)前節(jié)點(diǎn) head = head->next; // 移動(dòng)到下一個(gè)節(jié)點(diǎn) free(tmp); // 釋放當(dāng)前節(jié)點(diǎn)內(nèi)存 } } // 主函數(shù):程序入口 int main(void) { // 初始化無(wú)序數(shù)組 int values[] = {1, 5, 3, 7, 9, 5, 8, 5, 3}; int n = sizeof(values) / sizeof(values[0]); // 計(jì)算數(shù)組元素個(gè)數(shù) Node *head = NULL; // 初始化鏈表頭指針為空 // 將數(shù)組中所有元素按從大到小順序插入鏈表 for (int i = 0; i < n; i++) { insert_descending(&head, values[i]); } printf("初始有序鏈表(從大到?。篭n"); print_list(head); // 輸出插入后的鏈表內(nèi)容 // 刪除鏈表中所有值為 3 的節(jié)點(diǎn) delete_value(&head, 3); printf("刪除所有值為 3 后的鏈表:\n"); print_list(head); // 釋放鏈表占用的所有內(nèi)存 free_list(head); return 0; // 程序正常結(jié)束 }

得分 100
學(xué)習(xí)任務(wù)

浪潮君 的學(xué)生作業(yè):

#include // 標(biāo)準(zhǔn)輸入輸出庫(kù),提供 printf 等函數(shù) #include // 標(biāo)準(zhǔn)庫(kù),提供 malloc、free、exit 等函數(shù) // 定義鏈表節(jié)點(diǎn)結(jié)構(gòu)體 typedef struct Node { int data; // 節(jié)點(diǎn)存儲(chǔ)的整數(shù)數(shù)據(jù) struct Node *next; // 指向下一個(gè)節(jié)點(diǎn)的指針 } Node; // 創(chuàng)建一個(gè)新節(jié)點(diǎn),傳入數(shù)據(jù)值,返回節(jié)點(diǎn)指針 Node *create_node(int value) { Node *new_node = (Node *)malloc(sizeof(Node)); // 為新節(jié)點(diǎn)分配內(nèi)存空間 if (!new_node) { // 判斷內(nèi)存分配是否成功 perror("內(nèi)存分配失敗"); // 輸出錯(cuò)誤信息 exit(EXIT_FAILURE); // 退出程序,返回錯(cuò)誤碼 } new_node->data = value; // 設(shè)置節(jié)點(diǎn)數(shù)據(jù)域 new_node->next = NULL; // 初始化節(jié)點(diǎn)的下一個(gè)指針為 NULL(尾節(jié)點(diǎn)) return new_node; // 返回新節(jié)點(diǎn)指針 } // 尾插法:將節(jié)點(diǎn)插入鏈表尾部,保持元素插入順序 void append_node(Node **head, int value) { Node *new_node = create_node(value); // 創(chuàng)建新節(jié)點(diǎn) if (*head == NULL) { // 如果鏈表為空,新節(jié)點(diǎn)即為頭節(jié)點(diǎn) *head = new_node; return; } Node *current = *head; // 從頭節(jié)點(diǎn)開(kāi)始遍歷 while (current->next != NULL) { // 遍歷找到最后一個(gè)節(jié)點(diǎn) current = current->next; } current->next = new_node; // 將新節(jié)點(diǎn)掛到尾節(jié)點(diǎn)后面 } // 反轉(zhuǎn)鏈表,改變鏈表節(jié)點(diǎn)指向,實(shí)現(xiàn)逆序 void reverse_list(Node **head) { Node *prev = NULL; // 記錄當(dāng)前節(jié)點(diǎn)的前一個(gè)節(jié)點(diǎn),初始化為 NULL Node *curr = *head; // 當(dāng)前遍歷的節(jié)點(diǎn),初始化為頭節(jié)點(diǎn) Node *next = NULL; // 臨時(shí)指針,保存當(dāng)前節(jié)點(diǎn)的下一個(gè)節(jié)點(diǎn)地址 while (curr != NULL) { // 遍歷整個(gè)鏈表 next = curr->next; // 先保存當(dāng)前節(jié)點(diǎn)的下一個(gè)節(jié)點(diǎn) curr->next = prev; // 當(dāng)前節(jié)點(diǎn)的 next 指向前一個(gè)節(jié)點(diǎn),實(shí)現(xiàn)反轉(zhuǎn) prev = curr; // prev 向后移動(dòng),變成當(dāng)前節(jié)點(diǎn) curr = next; // curr 向后移動(dòng),變成原來(lái)下一個(gè)節(jié)點(diǎn) } *head = prev; // 最后 prev 指向新的頭節(jié)點(diǎn),更新鏈表頭指針 } // 遍歷鏈表并打印所有節(jié)點(diǎn)數(shù)據(jù) void print_list(Node *head) { printf("鏈表內(nèi)容:"); Node *current = head; // 臨時(shí)指針,從頭節(jié)點(diǎn)開(kāi)始遍歷 while (current != NULL) { printf("%d ", current->data); // 打印當(dāng)前節(jié)點(diǎn)的數(shù)據(jù) current = current->next; // 移動(dòng)到下一個(gè)節(jié)點(diǎn) } printf("\n"); // 輸出換行 } // 釋放鏈表占用的動(dòng)態(tài)內(nèi)存,防止內(nèi)存泄漏 void free_list(Node *head) { Node *tmp; while (head != NULL) { tmp = head; // 保存當(dāng)前節(jié)點(diǎn)指針 head = head->next; // 移動(dòng)到下一個(gè)節(jié)點(diǎn) free(tmp); // 釋放當(dāng)前節(jié)點(diǎn)內(nèi)存 } } // 主函數(shù),程序入口 int main(void) { int values[] = {1, 5, 3, 7, 9}; // 初始化數(shù)據(jù)數(shù)組 int n = sizeof(values) / sizeof(values[0]); // 計(jì)算數(shù)組元素?cái)?shù)量 Node *head = NULL; // 初始化鏈表頭指針為空 // 依次將數(shù)組中的元素插入鏈表尾部 for (int i = 0; i < n; i++) { append_node(&head, values[i]); } printf("原始鏈表:\n"); print_list(head); // 打印鏈表內(nèi)容(順序) reverse_list(&head); // 反轉(zhuǎn)鏈表,實(shí)現(xiàn)逆序 printf("逆序后鏈表:\n"); print_list(head); // 打印逆序后的鏈表內(nèi)容 free_list(head); // 釋放鏈表內(nèi)存,避免泄漏 return 0; // 程序正常結(jié)束 }

得分 100
討論題

浪潮君 的學(xué)生作業(yè):

#include // 標(biāo)準(zhǔn)輸入輸出函數(shù)庫(kù)(如 printf) #include // 動(dòng)態(tài)內(nèi)存分配和釋放函數(shù)庫(kù)(如 malloc、free) // 定義單向鏈表的節(jié)點(diǎn)結(jié)構(gòu)體 typedef struct Node { int data; // 數(shù)據(jù)域:保存整數(shù)數(shù)據(jù) struct Node *next; // 指針域:指向下一個(gè)節(jié)點(diǎn) } Node; // 創(chuàng)建一個(gè)新節(jié)點(diǎn),并返回指向該節(jié)點(diǎn)的指針 Node *create_node(int value) { Node *new_node = (Node *) malloc(sizeof(Node)); // 分配一個(gè)新節(jié)點(diǎn)的內(nèi)存 new_node->data = value; // 設(shè)置數(shù)據(jù)域 new_node->next = NULL; // 初始時(shí)不指向其他節(jié)點(diǎn) return new_node; // 返回新節(jié)點(diǎn)地址 } // 向鏈表中按從大到小順序插入一個(gè)新節(jié)點(diǎn) void insert_descending(Node **head, int value) { Node *new_node = create_node(value); // 創(chuàng)建新節(jié)點(diǎn) // 情況一:鏈表為空,或新值大于頭節(jié)點(diǎn),插入到鏈表頭部 if (*head == NULL || value > (*head)->data) { new_node->next = *head; // 新節(jié)點(diǎn)指向原頭節(jié)點(diǎn) *head = new_node; // 更新頭指針為新節(jié)點(diǎn) return; } // 情況二:尋找插入位置,插入到合適的節(jié)點(diǎn)之后 Node *current = *head; while (current->next != NULL && current->next->data >= value) { current = current->next; // 向后遍歷,直到找到插入點(diǎn) } // 在 current 節(jié)點(diǎn)之后插入新節(jié)點(diǎn) new_node->next = current->next; current->next = new_node; } // 打印鏈表中的所有節(jié)點(diǎn)值 void print_list(Node *head) { printf("鏈表內(nèi)容(從大到?。?quot;); Node *current = head; while (current != NULL) { printf("%d ", current->data); // 打印當(dāng)前節(jié)點(diǎn)的值 current = current->next; // 移動(dòng)到下一個(gè)節(jié)點(diǎn) } printf("\n"); } // 釋放鏈表占用的動(dòng)態(tài)內(nèi)存 void free_list(Node *head) { Node *tmp; while (head != NULL) { tmp = head; // 保存當(dāng)前節(jié)點(diǎn) head = head->next; // 移動(dòng)到下一個(gè)節(jié)點(diǎn) free(tmp); // 釋放當(dāng)前節(jié)點(diǎn) } } // 主函數(shù):程序入口 int main() { int values[] = {1, 5, 3, 7, 9}; // 待插入的無(wú)序整數(shù)數(shù)組 int n = sizeof(values) / sizeof(values[0]); // 計(jì)算數(shù)組長(zhǎng)度 Node *head = NULL; // 初始化鏈表頭指針為空 // 將數(shù)組中的每個(gè)元素按順序插入鏈表(保持從大到?。? for (int i = 0; i < n; ++i) { insert_descending(&head, values[i]); } // 打印鏈表內(nèi)容 print_list(head); // 釋放鏈表內(nèi)存 free_list(head); return 0; // 程序正常結(jié)束 }

得分 100
學(xué)習(xí)任務(wù)

Yam8632482 的學(xué)生作業(yè):

#include char * design_array(int * len) { static char a[100] = {0}; *len = sizeof(a)/sizeof(a[0]); return a; } void input_array(char *p) { printf(“input string:”); gets§; } void output_array(char * p) { for (int i = 0; p[i] != ‘\0’; i++) { printf("%c “,p[i]); } printf(”\n"); } int cout_space(char * p) { int sp =0; for (int i = 0; p[i] != ‘\0’; i++) { if (p[i] == ’ ') { sp++; } } return sp; } int main(void) { // (1)要求大家是設(shè)計(jì)?個(gè)design_arary()函數(shù),自己定義返回值和參數(shù)。 // 要求design_array()函數(shù)中定義一個(gè),static char a[100] = {0};,然后 把數(shù)組首地址和長(zhǎng)度返回。 char *p = NULL; int alen; p = design_array(&alen); printf(“p = %p, alen = %d\n”, p, alen); printf(“a = %s\n”, p); // (2)設(shè)計(jì)一個(gè)input_array()函數(shù),自定義返回和參數(shù),要求用戶從鍵盤(pán) 輸入任意的字符串,存放到a數(shù)組中 input_array(p); // (3)設(shè)計(jì)一個(gè)output_array()函數(shù),要求輸出a數(shù)組中的每一個(gè)字符, 以空格作為區(qū)分. w u h a n s h a n g h a i output_array(p); // (4)設(shè)計(jì)一個(gè)cout_space()函數(shù),自定義返回和參數(shù),要求用戶統(tǒng)計(jì)數(shù)組a中用戶 輸入的空格個(gè)數(shù),并返回值給main函數(shù)。 int count = cout_space(p); // (5)main()函數(shù)調(diào)用以上函數(shù),并輸出空格個(gè)數(shù)。 printf("空格個(gè)數(shù)是:%d\n", count); return 0; }

微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)