Your SlideShare is downloading. ×
寫程式?那些老師沒教的事
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

寫程式?那些老師沒教的事

1,083
views

Published on

寫程式?那些老師沒教的事 …

寫程式?那些老師沒教的事
畢玉泉 (小畢/CrBoy) <crboy>

Published in: Education

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,083
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
30
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. eleaseR 寫程式?那些老師沒教的事 Code Smart, Don’t Code Hard 2012/07/15 @StudyArea-Taichung 畢玉泉 (小畢/CrBoy) <crboy@crboy.net>
  • 2. 在開始之前...別怕!多問問題!今天只做粗淺簡介,但很歡迎深入討論!如果出現冷笑話...要笑!自由進出上廁所講手機或睡覺多問問題! 別怕!萬一講太久可以發問「請問幾點下課?」XD
  • 3. 我是誰?
  • 4. 經歷2007 年成大資工系程式設計競賽-優等2007 年全國大專電腦軟體設計競賽甲組-佳作2007 年 ACM ICPC 亞洲區台灣賽區-第 13 名2008 年第三屆南區大專院校程式設計競賽-進階組第一名2008 年成大資工系程式設計競賽進階組-第一名協辦 Ubuntu-TW 社群全台相關活動 2007 - 迄今2008 年間,於系內自行主講數場 C 語言基礎觀念教學課程2008 年全國大專電腦軟體設計競賽甲組-第三名主講「U很大,U不用錢 - Ubuntu Linux 介紹」於國立成功大學 (http://goo.gl/lEnCN) 2009/03/24主講「MozTW & Ubuntu 自由新生代」於高雄應用科技大學 (http://goo.gl/CgtBK) 2009/07/13主講「Ubuntu Linux 簡介」於台南四校資訊社團聯合迎新 2009/10/31「自由軟體應用與教學」於雲林縣口湖國小 2010/01/212010 年台灣駭客年會 場務組工作人員Ubuntu-TW 社群文件組(Doc Team)負責人 2010/10 - 迄今2011 年台灣駭客年會 場務組工作人員2011 年開源人年會 場務組工作人員2011 年資安技能金盾獎-第三名主講「那些老師沒教的事 - Code Smart, Don’t Code hard」於國立成功大學 2012/03/29
  • 5. 現在是打雜的
  • 6. 那...你是誰?
  • 7. 你為什麼在這?
  • 8. 今天我們以 C 語言為主
  • 9. 有空的話再來點 PHP
  • 10. 我們以前都怎麼寫程式的?
  • 11. ??
  • 12. 那.....Debug呢?
  • 13. 測試訊息印太多?
  • 14. 程式還是怪怪的....?
  • 15. 你真的很努力.....(默)
  • 16. 我有時候很愛用 XDrz debug 法printf("XD");/* do many things */printf("rzn"); 如果沒身體就是某個地方爆掉了XD XD    也是一招
  • 17. 老師:「努力是會有回報的!...........多寫一個功能加10分」
  • 18. 你又開始努力....
  • 19. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("h2°G"); * node *a, *b, *c; * * * * print_list(h2); * if(h==NULL || h->next==NULL) return h;/ * * * * h = Merge(h1, h2); * a = h;****************************************************************************** * * * * h1 = h2 = NULL; * b = a->next;* * * * * break; * c = b->next;FileName: hw7_s.c * * * case 7: * a->next = NULL;Programmer: CrBoy * * * * if(order) Split(&h, &h1, &h2); * while(c!=NULL){Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ * * * * else{ * * b->next = a;Input: * * * * * h = Reverse(h); * * a = b;Output: the standard out * * * * * Split(&h, &h1, &h2); * * b = c;Compilation: gcc hw7_s.c -o hw7_s * * * * } * * c = c->next;Run: ./hw7_s * * * * printf("h1°G"); * }Date: 2006/1/8 * * * * print_list(h1); * b->next = a;/ * * * * printf("h2°G"); * order = !order;****************************************************************************** * * * * print_list(h2); * return b;/ * * * * break; } * * * default: printf("±z™∫øȧJ¶≥ª~°In");#include <stdio.h> * * * case 8: help(); node *Merge(node *h1, node *h2){ * * } * node *h, *temp;struct node{ * } * h = temp = h1->data < h2->data ? h1 : h2;* int data; * return 0; * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);* struct node *next; } * while(h1!=NULL && h2!=NULL){}; * * temp = temp->next = h1->data < h2->data ? h1 : h2; void print_list(node *h){ * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);typedef struct node node; * node *temp; * } * temp = h; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * while(temp != NULL){ * return h;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * printf("%d -> ", temp->data); }°§Jdata®√¶^∂«∑s™∫h*/ * * temp = temp->next;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * } void Split(node **h, node **h1_ptr, node **h2_ptr){£data®√¶^∂«∑s™∫h*/ * printf("NULLn"); * node *h1=NULL, *h2=NULL;node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß } * while(*h!=NULL){‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * if((*h)->data%2){int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ node *Insert(int data, node *h){ * * * if(h1==NULL) h1 = *h1_ptr = *h;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * node *p, *t, *temp; * * * else *h1_ptr = (*h1_ptr)->next = *h;node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked * if(h==NULL){ * * }else{list®√¶^∂«¶X®÷´·™∫™∫head*/ * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ * * temp->next = NULL; * * }void help(); * * return temp; * * *h = (*h)->next; * } * }int order=1; * p = h; * (*h1_ptr)->next = (*h2_ptr)->next = NULL; * t = h->next; * *h1_ptr = h1;int main(void){ * if(data<p->data){ * *h2_ptr = h2;* int sel=8, data=0; * * temp = (node*)malloc(sizeof(node)); * *h = NULL;* node *h=NULL, *h1=NULL, *h2=NULL; * * temp->data = data; }* help(); * * temp->next = p;* while(sel){ * * return temp; void help(){* * printf("n•ÿ´e™∫Linked list°G"); * } * printf("0.µ≤ßÙn");* * print_list(h); * if(t!=NULL) * printf("1.Insertn");* * printf("Ω–øÔ拕؇°G"); * * while(data<p->data || data>t->data){ * printf("2.Deleten");* * if(scanf("%d", &sel)==0){ * * * p = p->next; * printf("3.Searchn");* * * sel=-1; * * * t = t->next; * printf("4.Countn");* * * fflush(stdin); * * * if(t==NULL) break; * printf("5.Reversen");* * } * * } * printf("6.Mergen");* * switch(sel){ * temp = (node*)malloc(sizeof(node)); * printf("7.Splitn");* * * case 0: break; * temp->data = data; * printf("8.helpn");* * * case 1: * temp->next = p->next; }* * * * printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * p->next = temp;* * * * if(scanf("%d", &data)==0) continue; * return h;* * * * if(order) }* * * * * h = Insert(data, h);* * * * else{ node *Delete(int data, node *h){* * * * * h = Reverse(h); * node *p, *t;* * * * * h = Insert(data, h); * if(h==NULL) return h;* * * * * h = Reverse(h); * p = h;* * * * } * t = h->next;* * * * break; * if(data == p->data){* * * case 2: * * p = p->next;* * * * printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * * free(h);* * * * if(scanf("%d", &data)==0) continue; * * return p;* * * * if(order) * }* * * * * h = Delete(data, h); * while(data!=t->data){* * * * else{ * * p = p->next;* * * * * h = Reverse(h); * * t = t->next;* * * * * h = Delete(data, h); * * if(t==NULL) return h;* * * * * h = Reverse(h); * }* * * * } * p->next = t->next;* * * * break; * free(t);* * * case 3: * return h;* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); }* * * * if(scanf("%d", &data)==0) continue;* * * * h1 = Search(data, h); node *Search(int data, node *h){* * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * node *p=h;data); * while(p!=NULL && data!=p->data)* p = p->next;* * * * print_list(h1); * return p;* * * * h1 = NULL; }* * * * break;* * * case 4: int Count(node *h){* * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * int count=0;°Cn", Count(h)); * while(h!=NULL){* * * * break; * * count += 1;* * * case 5: * * h = h->next;* * * * h = Reverse(h); * }* * * * break; * return count;* * * case 6: }* * * * printf("h1°G");* * * * print_list(h1); node *Reverse(node *h){
  • 20. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * return h; data); }/ * * * * print_list(h1);****************************************************************************** * * * * h1 = NULL; node *Search(int data, node *h){* * * * * break; * node *p=h;FileName: hw7_s.c * * * case 4: * while(p!=NULL && data!=p->data)* p = p->next;Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return p;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: int Count(node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); * int count=0;Run: ./hw7_s * * * * break; * while(h!=NULL){Date: 2006/1/8 * * * case 6: * * count += 1;/ * * * * printf("h1°G"); * * h = h->next;****************************************************************************** * * * * print_list(h1); * }/ * * * * printf("h2°G"); * return count; * * * * print_list(h2); }#include <stdio.h> * * * * h = Merge(h1, h2); * * * * h1 = h2 = NULL; node *Reverse(node *h){struct node{ * * * * break; * node *a, *b, *c;* int data; * * * case 7: * if(h==NULL || h->next==NULL) return h;* struct node *next; * * * * if(order) Split(&h, &h1, &h2); * a = h;}; * * * * else{ * b = a->next; * * * * * h = Reverse(h); * c = b->next;typedef struct node node; * * * * * Split(&h, &h1, &h2); * a->next = NULL; 新增! * * * * } * while(c!=NULL){void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); * * b->next = a;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); * * a = b;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); * * b = c;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); * * c = c->next;£data®√¶^∂«∑s™∫h*/ * * * * break; * }node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); * b->next = a;‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); * order = !order; 新增!int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } * return b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } }node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node));list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; node *Merge(node *h1, node *h2){void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * node *h, *temp;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * h = temp = h1->data < h2->data ? h1 : h2;void help(); * return 0; * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); } * while(h1!=NULL && h2!=NULL){int order=1; * * temp = temp->next = h1->data < h2->data ? h1 : h2; void print_list(node *h){ * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);int main(void){ * node *temp; * }! node *h1=NULL, *h2=NULL; * temp = h; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! while(*h!=NULL){ * while(temp != NULL){ * return h;! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); }! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } void Split(node **h, node **h1_ptr, node **h2_ptr){! ! }else{ * printf("NULLn"); * node *h1=NULL, *h2=NULL;! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } * while(*h!=NULL){! ! ! else *h2_ptr = (*h2_ptr)->next = *h; * * if((*h)->data%2){! ! } node *Insert(int data, node *h){ * * * if(h1==NULL) h1 = *h1_ptr = *h;! ! *h = (*h)->next; * node *p, *t, *temp; * * * else *h1_ptr = (*h1_ptr)->next = *h;! } * if(h==NULL){ * * }else{! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;! *h1_ptr = h1; * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;! *h2_ptr = h2; * * temp->next = NULL; * * }! *h = NULL; * * return temp; * * *h = (*h)->next;* int sel=8, data=0; * } * }* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; * (*h1_ptr)->next = (*h2_ptr)->next = NULL;* help(); * t = h->next; * *h1_ptr = h1;* while(sel){ * if(data<p->data){ * *h2_ptr = h2;* * printf("n•ÿ´e™∫Linked list°G"); * * temp = (node*)malloc(sizeof(node)); * *h = NULL;* * print_list(h); * * temp->data = data; }* * printf("Ω–øÔ拕؇°G"); * * temp->next = p;* * if(scanf("%d", &sel)==0){ * * return temp; void help(){* * * sel=-1; * } * printf("0.µ≤ßÙn");* * * fflush(stdin); * if(t!=NULL) * printf("1.Insertn");* * } * * while(data<p->data || data>t->data){ * printf("2.Deleten");* * switch(sel){ * * * p = p->next; * printf("3.Searchn");* * * case 0: break; * * * t = t->next; * printf("4.Countn");* * * case 1: * * * if(t==NULL) break; * printf("5.Reversen");* * * * printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * } * printf("6.Mergen");* * * * if(scanf("%d", &data)==0) continue; * temp = (node*)malloc(sizeof(node)); * printf("7.Splitn");* * * * if(order) * temp->data = data; * printf("8.helpn");* * * * * h = Insert(data, h); * temp->next = p->next; }* * * * else{ * p->next = temp;* * * * * h = Reverse(h); * return h;* * * * * h = Insert(data, h); }* * * * * h = Reverse(h);* * * * } node *Delete(int data, node *h){* * * * break; * node *p, *t;* * * case 2: * if(h==NULL) return h;* * * * printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * p = h;* * * * if(scanf("%d", &data)==0) continue; * t = h->next;* * * * if(order) * if(data == p->data){* * * * * h = Delete(data, h); * * p = p->next;* * * * else{ * * free(h);* * * * * h = Reverse(h); * * return p;* * * * * h = Delete(data, h); * }* * * * * h = Reverse(h); * while(data!=t->data){* * * * } * * p = p->next;* * * * break; * * t = t->next;* * * case 3: * * if(t==NULL) return h;* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * }* * * * if(scanf("%d", &data)==0) continue; * p->next = t->next;* * * * h1 = Search(data, h); * free(t);
  • 21. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * return h; data); }/ * * * * print_list(h1);****************************************************************************** * * * * h1 = NULL; node *Search(int data, node *h){* * * * * break; * node *p=h;FileName: hw7_s.c * * * case 4: * while(p!=NULL && data!=p->data)* p = p->next;Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return p;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: int Count(node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); * int count=0;Run: ./hw7_s * * * * break; * while(h!=NULL){Date: 2006/1/8 * * * case 6: * * count += 1;/ * * * * printf("h1°G"); * * h = h->next;****************************************************************************** * * * * print_list(h1); * } 刪除!/ * * * * printf("h2°G"); * return count; * * * * print_list(h2); }#include <stdio.h> * * * * h = Merge(h1, h2); * * * * h1 = h2 = NULL; node *Reverse(node *h){struct node{ * * * * break; * node *a, *b, *c;* int data; * * * case 7: * if(h==NULL || h->next==NULL) return h;* struct node *next; * * * * if(order) Split(&h, &h1, &h2); * a = h;}; * * * * else{ * b = a->next; * * * * * h = Reverse(h); * c = b->next;typedef struct node node; * * * * * Split(&h, &h1, &h2); * a->next = NULL; * * * * } ! while(c!=NULL){void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); ! ! b->next = a;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); ! ! a = b;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); ! ! b = c;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); ! ! c = c->next;£data®√¶^∂«∑s™∫h*/ * * * * break; ! }node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); * b->next = a;‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); * order = !order;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } * return b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } }node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node));list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; node *Merge(node *h1, node *h2){void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * node *h, *temp;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * h = temp = h1->data < h2->data ? h1 : h2;void help(); * return 0; * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); } * while(h1!=NULL && h2!=NULL){int order=1; * * temp = temp->next = h1->data < h2->data ? h1 : h2; void print_list(node *h){ * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);int main(void){ * node *temp; * }! node *h1=NULL, *h2=NULL; * temp = h; ! while(c!=NULL){! while(*h!=NULL){ * while(temp != NULL){ ! ! b->next = a;! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); ! ! a = b;! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next; ! ! b = c;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } ! ! c = c->next;! ! }else{ * printf("NULLn"); ! }! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! ! ! else *h2_ptr = (*h2_ptr)->next = *h; * return h;! ! } node *Insert(int data, node *h){ } 新增!! ! *h = (*h)->next; * node *p, *t, *temp;! } * if(h==NULL){ void Split(node **h, node **h1_ptr, node **h2_ptr){! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); * node *h1=NULL, *h2=NULL;! *h1_ptr = h1; * * temp->data = data; * while(*h!=NULL){! *h2_ptr = h2; * * temp->next = NULL; * * if((*h)->data%2){! *h = NULL; * * return temp; * * * if(h1==NULL) h1 = *h1_ptr = *h;* int sel=8, data=0; * } * * * else *h1_ptr = (*h1_ptr)->next = *h;* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; * * }else{* help(); * t = h->next; * * * if(h2==NULL) h2 = *h2_ptr = *h;* while(sel){ * if(data<p->data){ * * * else *h2_ptr = (*h2_ptr)->next = *h;* * printf("n•ÿ´e™∫Linked list°G"); * * temp = (node*)malloc(sizeof(node)); * * }* * print_list(h); * * temp->data = data; * * *h = (*h)->next;* * printf("Ω–øÔ拕؇°G"); * * temp->next = p; * }* * if(scanf("%d", &sel)==0){ * * return temp; * (*h1_ptr)->next = (*h2_ptr)->next = NULL;* * * sel=-1; * } * *h1_ptr = h1;* * * fflush(stdin); * if(t!=NULL) * *h2_ptr = h2;* * } * * while(data<p->data || data>t->data){ * *h = NULL;* * switch(sel){ * * * p = p->next; }* * * case 0: break; * * * t = t->next;* * * case 1: * * * if(t==NULL) break; void help(){* * * * printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * } * printf("0.µ≤ßÙn");* * * * if(scanf("%d", &data)==0) continue; * temp = (node*)malloc(sizeof(node)); * printf("1.Insertn");* * * * if(order) * temp->data = data; * printf("2.Deleten");* * * * * h = Insert(data, h); * temp->next = p->next; * printf("3.Searchn");* * * * else{ * p->next = temp; * printf("4.Countn");* * * * * h = Reverse(h); * return h; * printf("5.Reversen");* * * * * h = Insert(data, h); } * printf("6.Mergen");* * * * * h = Reverse(h); * printf("7.Splitn");* * * * } node *Delete(int data, node *h){ * printf("8.helpn");* * * * break; * node *p, *t; }* * * case 2: * if(h==NULL) return h;* * * * printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * p = h;* * * * if(scanf("%d", &data)==0) continue; * t = h->next;* * * * if(order) * if(data == p->data){* * * * * h = Delete(data, h); * * p = p->next;* * * * else{ * * free(h);* * * * * h = Reverse(h); * * return p;* * * * * h = Delete(data, h); * }* * * * * h = Reverse(h); * while(data!=t->data){* * * * } * * p = p->next;* * * * break; * * t = t->next;* * * case 3: * * if(t==NULL) return h;* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * }* * * * if(scanf("%d", &data)==0) continue; * p->next = t->next;* * * * h1 = Search(data, h); * free(t);
  • 22. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * * p = p->next; data); * * t = t->next;/ * * * * print_list(h1); * * if(t==NULL) return h;****************************************************************************** * * * * h1 = NULL; * }* * * * * break; * p->next = t->next;FileName: hw7_s.c * * * case 4: * free(t);Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return h;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: node *Search(int data, node *h){ 刪除!Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); ! node *p=h;Run: ./hw7_s * * * * break; ! while(p!=NULL && data!=p->data)! p = p->next;Date: 2006/1/8 * * * case 6: ! return p;/ * * * * printf("h1°G"); }****************************************************************************** * * * * print_list(h1);/ * * * * printf("h2°G"); int Count(node *h){ * * * * print_list(h2); ! int count=0;#include <stdio.h> * * * * h = Merge(h1, h2); ! while(h!=NULL){ * * * * h1 = h2 = NULL; ! ! count += 1;struct node{ * * * * break; ! ! h = h->next;* int data; * * * case 7: ! }* struct node *next; * * * * if(order) Split(&h, &h1, &h2); ! return count;}; * * * * else{ } * * * * * h = Reverse(h);typedef struct node node; * * * * * Split(&h, &h1, &h2); node *Reverse(node *h){ * * * * } * node *a, *b, *c;void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); * if(h==NULL || h->next==NULL) return h;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); * a = h;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); * b = a->next;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); * c = b->next;£data®√¶^∂«∑s™∫h*/ * * * * break; * a->next = NULL;node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); ! while(c!=NULL){‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); ! ! b->next = a;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } ! ! a = b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } ! ! b = c;node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node)); ! ! c = c->next;list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; ! }void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * b->next = a;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * order = !order;void help(); * return 0; * return b; } }int order=1; void print_list(node *h){ node *Merge(node *h1, node *h2){int main(void){ * node *temp; * node *h, *temp;! node *h1=NULL, *h2=NULL; * temp = h; * h = temp = h1->data < h2->data ? h1 : h2;! while(*h!=NULL){ * while(temp != NULL){ * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); * while(h1!=NULL && h2!=NULL){! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next; * * temp = temp->next = h1->data < h2->data ? h1 : h2;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! }else{ * printf("NULLn"); * }! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } ! while(c!=NULL){! ! ! else *h2_ptr = (*h2_ptr)->next = *h; ! ! b->next = a;! ! } node *Insert(int data, node *h){ ! ! a = b;! ! *h = (*h)->next; * node *p, *t, *temp; ! ! b = c;! } * if(h==NULL){ ! ! c = c->next;! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); ! }! *h1_ptr = h1; * * temp->data = data; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! *h2_ptr = h2; * * temp->next = NULL; * return h;! *h = NULL; * * return temp; } 刪除!* int sel=8, data=0; * }* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; void Split(node **h, node **h1_ptr, node **h2_ptr){* help(); ! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * node *h1=NULL, *h2=NULL;* while(sel){ ! *h1_ptr = h1; * while(*h!=NULL){* * printf("n•ÿ´e™∫Linked list°G"); ! *h2_ptr = h2; * * if((*h)->data%2){* * print_list(h); ! *h = NULL; * * * if(h1==NULL) h1 = *h1_ptr = *h;* * printf("Ω–øÔ拕؇°G"); * t = h->next; * * * else *h1_ptr = (*h1_ptr)->next = *h;* * if(scanf("%d", &sel)==0){ * if(data<p->data){ * * }else{* * * sel=-1; * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h; 新增!* * * fflush(stdin); * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;* * } * * temp->next = p; * * }* * switch(sel){ * * return temp; * * *h = (*h)->next;* * * case 0: break; * } * }! ! ! case 1: * if(t!=NULL) * (*h1_ptr)->next = (*h2_ptr)->next = NULL;! ! ! ! printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * while(data<p->data || data>t->data){ * *h1_ptr = h1;! ! ! ! if(scanf("%d", &data)==0) continue; * * * p = p->next; * *h2_ptr = h2;! ! ! ! if(order) * * * t = t->next; * *h = NULL;! ! ! ! ! h = Insert(data, h); * * * if(t==NULL) break; }! ! ! ! else{ * * }! ! ! ! ! h = Reverse(h); * temp = (node*)malloc(sizeof(node)); void help(){! ! ! ! ! h = Insert(data, h); * temp->data = data; * printf("0.µ≤ßÙn");! ! ! ! ! h = Reverse(h); * temp->next = p->next; * printf("1.Insertn");! ! ! ! } * p->next = temp; * printf("2.Deleten");! ! ! ! break; ! node *h=NULL, *h1=NULL, *h2=NULL; * printf("3.Searchn");! ! ! case 2: ! help(); * printf("4.Countn");! ! ! ! printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * return h; * printf("5.Reversen");! ! ! ! if(scanf("%d", &data)==0) continue; } * printf("6.Mergen");! ! ! ! if(order) * printf("7.Splitn");! ! ! ! ! h = Delete(data, h); node *Delete(int data, node *h){ * printf("8.helpn");! ! ! ! else{ * node *p, *t; }! ! ! ! ! h = Reverse(h); * if(h==NULL) return h;! ! ! ! ! h = Delete(data, h); * p = h;! ! ! ! ! h = Reverse(h); * t = h->next;! ! ! ! } * if(data == p->data){! ! ! ! break; * * p = p->next;* * * case 3: * * free(h);* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * * return p;* * * * if(scanf("%d", &data)==0) continue; * }* * * * h1 = Search(data, h); * while(data!=t->data){
  • 23. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * * p = p->next; data); * * t = t->next;/ * * * * print_list(h1); * * if(t==NULL) return h;****************************************************************************** * * * * h1 = NULL; * }* * * * * break; * p->next = t->next;FileName: hw7_s.c * * * case 4: * free(t);Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return h;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: node *Search(int data, node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); ! node *p=h;Run: ./hw7_s * * * * break; ! while(p!=NULL && data!=p->data)! p = p->next;Date: 2006/1/8 * * * case 6: ! return p;/ * * * * printf("h1°G"); }****************************************************************************** * * * * print_list(h1);/ * * * * printf("h2°G"); int Count(node *h){ * * * * print_list(h2); ! int count=0;#include <stdio.h> * * * * h = Merge(h1, h2); ! while(h!=NULL){ * * * * h1 = h2 = NULL; ! ! count += 1;struct node{ * * * * break; ! ! h = h->next;* int data; * * * case 7: ! }* struct node *next; * * * * if(order) Split(&h, &h1, &h2); ! return count;}; * * * * else{ } * * * * * h = Reverse(h);typedef struct node node; * * * * * Split(&h, &h1, &h2); node *Reverse(node *h){ * * * * } * node *a, *b, *c;void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); * if(h==NULL || h->next==NULL) return h;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); * a = h;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); * b = a->next;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); * c = b->next; 刪除!£data®√¶^∂«∑s™∫h*/ * * * * break; * a->next = NULL;node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); ! while(c!=NULL){‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); ! ! b->next = a;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } ! ! a = b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } ! ! b = c;node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node)); ! ! c = c->next;list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; ! }void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * b->next = a;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * order = !order;void help(); * return 0; * return b; } }int order=1; void print_list(node *h){ node *Merge(node *h1, node *h2){int main(void){ * node *temp; * node *h, *temp;! node *h1=NULL, *h2=NULL; * temp = h; * h = temp = h1->data < h2->data ? h1 : h2;! while(*h!=NULL){ * while(temp != NULL){ * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); * while(h1!=NULL && h2!=NULL){! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next; * * temp = temp->next = h1->data < h2->data ? h1 : h2;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! }else{ * printf("NULLn"); * }! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } ! while(c!=NULL){! ! ! else *h2_ptr = (*h2_ptr)->next = *h; ! ! b->next = a;! ! } node *Insert(int data, node *h){ ! ! a = b;! ! *h = (*h)->next; * node *p, *t, *temp; ! ! b = c;! } * if(h==NULL){ ! ! c = c->next;! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); ! }! *h1_ptr = h1; * * temp->data = data; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! *h2_ptr = h2; * * temp->next = NULL; * return h;! *h = NULL; * * return temp; }* int sel=8, data=0; * }* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; void Split(node **h, node **h1_ptr, node **h2_ptr){* help(); ! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * node *h1=NULL, *h2=NULL;* while(sel){ ! *h1_ptr = h1; * while(*h!=NULL){* * printf("n•ÿ´e™∫Linked list°G"); ! *h2_ptr = h2; * * if((*h)->data%2){* * print_list(h); ! *h = NULL; * * * if(h1==NULL) h1 = *h1_ptr = *h;* * printf("Ω–øÔ拕؇°G"); * t = h->next; * * * else *h1_ptr = (*h1_ptr)->next = *h;* * if(scanf("%d", &sel)==0){ * if(data<p->data){ * * }else{ 新增!* * * sel=-1; * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;* * * fflush(stdin); * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;* * } * * temp->next = p; * * }* * switch(sel){ * * return temp; * * *h = (*h)->next;* * * case 0: break; * } * }! ! ! case 1: * if(t!=NULL) * (*h1_ptr)->next = (*h2_ptr)->next = NULL;! ! ! ! printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * while(data<p->data || data>t->data){ * *h1_ptr = h1;! ! ! ! if(scanf("%d", &data)==0) continue; * * * p = p->next; * *h2_ptr = h2;! ! ! ! if(order) * * * t = t->next; * *h = NULL;! ! ! ! ! h = Insert(data, h); * * * if(t==NULL) break; }! ! ! ! else{ * * }! ! ! ! ! h = Reverse(h); * temp = (node*)malloc(sizeof(node)); void print_list(node *h){! ! ! ! ! h = Insert(data, h); * temp->data = data; ! node *temp;! ! ! ! ! h = Reverse(h); * temp->next = p->next; ! temp = h;! ! ! ! } * p->next = temp; ! while(temp != NULL){! ! ! ! break; ! node *h=NULL, *h1=NULL, *h2=NULL; ! ! printf("%d -> ", temp->data);! ! ! case 2: ! help(); ! ! temp = temp->next;! ! ! ! printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * return h; ! }! ! ! ! if(scanf("%d", &data)==0) continue; } ! printf("NULLn");! ! ! ! if(order) }! ! ! ! ! h = Delete(data, h); node *Delete(int data, node *h){! ! ! ! else{ * node *p, *t; void help(){! ! ! ! ! h = Reverse(h); * if(h==NULL) return h; * printf("0.µ≤ßÙn");! ! ! ! ! h = Delete(data, h); * p = h; * printf("1.Insertn");! ! ! ! ! h = Reverse(h); * t = h->next; * printf("2.Deleten");! ! ! ! } * if(data == p->data){ * printf("3.Searchn");! ! ! ! break; * * p = p->next; * printf("4.Countn");* * * case 3: * * free(h); * printf("5.Reversen");* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * * return p; * printf("6.Mergen");* * * * if(scanf("%d", &data)==0) continue; * } * printf("7.Splitn");* * * * h1 = Search(data, h); * while(data!=t->data){ * printf("8.helpn");
  • 24. 你花了兩天
  • 25. 結果功能寫爛了
  • 26. 又花兩天把code改回來
  • 27. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * * p = p->next; data); * * t = t->next;/ * * * * print_list(h1); * * if(t==NULL) return h;****************************************************************************** * * * * h1 = NULL; * }* * * * * break; * p->next = t->next;FileName: hw7_s.c * * * case 4: * free(t);Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return h;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: node *Search(int data, node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); ! node *p=h;Run: ./hw7_s * * * * break; ! while(p!=NULL && data!=p->data)! p = p->next;Date: 2006/1/8 * * * case 6: ! return p;/ * * * * printf("h1°G"); }****************************************************************************** * * * * print_list(h1);/ * * * * printf("h2°G"); int Count(node *h){ * * * * print_list(h2); ! int count=0;#include <stdio.h> * * * * h = Merge(h1, h2); ! while(h!=NULL){ * * * * h1 = h2 = NULL; ! ! count += 1;struct node{ * * * * break; ! ! h = h->next;* int data; * * * case 7: ! }* struct node *next; * * * * if(order) Split(&h, &h1, &h2); ! return count;}; * * * * else{ } * * * * * h = Reverse(h);typedef struct node node; * * * * * Split(&h, &h1, &h2); node *Reverse(node *h){ * * * * } * node *a, *b, *c;void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); * if(h==NULL || h->next==NULL) return h;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); * a = h;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); * b = a->next;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); * c = b->next;£data®√¶^∂«∑s™∫h*/ * * * * break; * a->next = NULL;node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); ! while(c!=NULL){‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); ! ! b->next = a;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } ! ! a = b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } ! ! b = c;node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node)); ! ! c = c->next;list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; ! }void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * b->next = a;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * order = !order;void help(); * return 0; * return b; } }int order=1; void print_list(node *h){ node *Merge(node *h1, node *h2){int main(void){ * node *temp; * node *h, *temp;! node *h1=NULL, *h2=NULL; * temp = h; * h = temp = h1->data < h2->data ? h1 : h2;! while(*h!=NULL){ * while(temp != NULL){ * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); * while(h1!=NULL && h2!=NULL){! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next; * * temp = temp->next = h1->data < h2->data ? h1 : h2;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! }else{ * printf("NULLn"); * }! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } ! while(c!=NULL){! ! ! else *h2_ptr = (*h2_ptr)->next = *h; ! ! b->next = a;! ! } node *Insert(int data, node *h){ ! ! a = b;! ! *h = (*h)->next; * node *p, *t, *temp; ! ! b = c;! } * if(h==NULL){ ! ! c = c->next;! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); ! }! *h1_ptr = h1; * * temp->data = data; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! *h2_ptr = h2; * * temp->next = NULL; * return h;! *h = NULL; * * return temp; }* int sel=8, data=0; * }* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; void Split(node **h, node **h1_ptr, node **h2_ptr){* help(); ! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * node *h1=NULL, *h2=NULL;* while(sel){ ! *h1_ptr = h1; * while(*h!=NULL){* * printf("n•ÿ´e™∫Linked list°G"); ! *h2_ptr = h2; * * if((*h)->data%2){* * print_list(h); ! *h = NULL; * * * if(h1==NULL) h1 = *h1_ptr = *h;* * printf("Ω–øÔ拕؇°G"); * t = h->next; * * * else *h1_ptr = (*h1_ptr)->next = *h;* * if(scanf("%d", &sel)==0){ * if(data<p->data){ * * }else{* * * sel=-1; * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;* * * fflush(stdin); * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;* * } * * temp->next = p; * * }* * switch(sel){ * * return temp; * * *h = (*h)->next;* * * case 0: break; * } * }! ! ! case 1: * if(t!=NULL) * (*h1_ptr)->next = (*h2_ptr)->next = NULL;! ! ! ! printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * while(data<p->data || data>t->data){ * *h1_ptr = h1;! ! ! ! if(scanf("%d", &data)==0) continue; * * * p = p->next; * *h2_ptr = h2;! ! ! ! if(order) * * * t = t->next; * *h = NULL;! ! ! ! ! h = Insert(data, h); * * * if(t==NULL) break; }! ! ! ! else{ * * }! ! ! ! ! h = Reverse(h); * temp = (node*)malloc(sizeof(node)); void print_list(node *h){! ! ! ! ! h = Insert(data, h); * temp->data = data; ! node *temp;! ! ! ! ! h = Reverse(h); * temp->next = p->next; ! temp = h;! ! ! ! } * p->next = temp; ! while(temp != NULL){! ! ! ! break; ! node *h=NULL, *h1=NULL, *h2=NULL; ! ! printf("%d -> ", temp->data);! ! ! case 2: ! help(); ! ! temp = temp->next;! ! ! ! printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * return h; ! }! ! ! ! if(scanf("%d", &data)==0) continue; } ! printf("NULLn");! ! ! ! if(order) }! ! ! ! ! h = Delete(data, h); node *Delete(int data, node *h){! ! ! ! else{ * node *p, *t; void help(){! ! ! ! ! h = Reverse(h); * if(h==NULL) return h; * printf("0.µ≤ßÙn");! ! ! ! ! h = Delete(data, h); * p = h; * printf("1.Insertn");! ! ! ! ! h = Reverse(h); * t = h->next; * printf("2.Deleten");! ! ! ! } * if(data == p->data){ * printf("3.Searchn");! ! ! ! break; * * p = p->next; * printf("4.Countn");* * * case 3: * * free(h); * printf("5.Reversen");* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * * return p; * printf("6.Mergen");* * * * if(scanf("%d", &data)==0) continue; * } * printf("7.Splitn");* * * * h1 = Search(data, h); * while(data!=t->data){ * printf("8.helpn");
  • 28. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * * p = p->next; data); * * t = t->next;/ * * * * print_list(h1); * * if(t==NULL) return h;****************************************************************************** * * * * h1 = NULL; * }* * * * * break; * p->next = t->next;FileName: hw7_s.c * * * case 4: * free(t);Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return h;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: node *Search(int data, node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); ! node *p=h;Run: ./hw7_s * * * * break; ! while(p!=NULL && data!=p->data)! p = p->next;Date: 2006/1/8 * * * case 6: ! return p;/ * * * * printf("h1°G"); }****************************************************************************** * * * * print_list(h1);/ * * * * printf("h2°G"); int Count(node *h){ * * * * print_list(h2); ! int count=0;#include <stdio.h> * * * * h = Merge(h1, h2); ! while(h!=NULL){ * * * * h1 = h2 = NULL; ! ! count += 1;struct node{ * * * * break; ! ! h = h->next;* int data; * * * case 7: ! }* struct node *next; * * * * if(order) Split(&h, &h1, &h2); ! return count;}; * * * * else{ } * * * * * h = Reverse(h);typedef struct node node; * * * * * Split(&h, &h1, &h2); node *Reverse(node *h){ * * * * } * node *a, *b, *c;void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); * if(h==NULL || h->next==NULL) return h;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); * a = h;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); * b = a->next;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); * c = b->next;£data®√¶^∂«∑s™∫h*/ * * * * break; * a->next = NULL;node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); ! while(c!=NULL){‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); ! ! b->next = a;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } ! ! a = b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } ! ! b = c;node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node)); ! ! c = c->next;list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; ! }void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * b->next = a;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * order = !order;void help(); * return 0; * return b; } }int order=1; void print_list(node *h){ node *Merge(node *h1, node *h2){int main(void){ * node *temp; * node *h, *temp;! node *h1=NULL, *h2=NULL; * temp = h; * h = temp = h1->data < h2->data ? h1 : h2;! while(*h!=NULL){ * while(temp != NULL){ * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); 改回來!! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); * while(h1!=NULL && h2!=NULL){! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next; * * temp = temp->next = h1->data < h2->data ? h1 : h2;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! }else{ * printf("NULLn"); * }! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } ! while(c!=NULL){! ! ! else *h2_ptr = (*h2_ptr)->next = *h; ! ! b->next = a;! ! } node *Insert(int data, node *h){ ! ! a = b;! ! *h = (*h)->next; * node *p, *t, *temp; ! ! b = c;! } * if(h==NULL){ ! ! c = c->next;! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); ! }! *h1_ptr = h1; * * temp->data = data; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! *h2_ptr = h2; * * temp->next = NULL; * return h;! *h = NULL; * * return temp; }* int sel=8, data=0; * }* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; void Split(node **h, node **h1_ptr, node **h2_ptr){* help(); ! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * node *h1=NULL, *h2=NULL;* while(sel){ ! *h1_ptr = h1; * while(*h!=NULL){* * printf("n•ÿ´e™∫Linked list°G"); ! *h2_ptr = h2; * * if((*h)->data%2){* * print_list(h); ! *h = NULL; * * * if(h1==NULL) h1 = *h1_ptr = *h;* * printf("Ω–øÔ拕؇°G"); * t = h->next; * * * else *h1_ptr = (*h1_ptr)->next = *h;* * if(scanf("%d", &sel)==0){ * if(data<p->data){ * * }else{* * * sel=-1; * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;* * * fflush(stdin); * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;* * } * * temp->next = p; * * }* * switch(sel){ * * return temp; * * *h = (*h)->next;* * * case 0: break; * } * }! ! ! case 1: * if(t!=NULL) * (*h1_ptr)->next = (*h2_ptr)->next = NULL;! ! ! ! printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * while(data<p->data || data>t->data){ * *h1_ptr = h1;! ! ! ! if(scanf("%d", &data)==0) continue; * * * p = p->next; * *h2_ptr = h2;! ! ! ! if(order) * * * t = t->next; * *h = NULL;! ! ! ! ! h = Insert(data, h); * * * if(t==NULL) break; }! ! ! ! else{ * * }! ! ! ! ! h = Reverse(h); * temp = (node*)malloc(sizeof(node)); void print_list(node *h){! ! ! ! ! h = Insert(data, h); * temp->data = data; ! node *temp;! ! ! ! ! h = Reverse(h); * temp->next = p->next; ! temp = h;! ! ! ! } * p->next = temp; ! while(temp != NULL){! ! ! ! break; ! node *h=NULL, *h1=NULL, *h2=NULL; ! ! printf("%d -> ", temp->data);! ! ! case 2: ! help(); ! ! temp = temp->next;! ! ! ! printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * return h; ! }! ! ! ! if(scanf("%d", &data)==0) continue; } ! printf("NULLn");! ! ! ! if(order) }! ! ! ! ! h = Delete(data, h); node *Delete(int data, node *h){! ! ! ! else{ * node *p, *t; void help(){! ! ! ! ! h = Reverse(h); * if(h==NULL) return h; * printf("0.µ≤ßÙn");! ! ! ! ! h = Delete(data, h); * p = h; * printf("1.Insertn");! ! ! ! ! h = Reverse(h); * t = h->next; * printf("2.Deleten");! ! ! ! } * if(data == p->data){ * printf("3.Searchn");! ! ! ! break; * * p = p->next; * printf("4.Countn");* * * case 3: * * free(h); * printf("5.Reversen");* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * * return p; * printf("6.Mergen");* * * * if(scanf("%d", &data)==0) continue; * } * printf("7.Splitn");* * * * h1 = Search(data, h); * while(data!=t->data){ * printf("8.helpn");
  • 29. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * * p = p->next; data); * * t = t->next;/ * * * * print_list(h1); * * if(t==NULL) return h;****************************************************************************** * * * * h1 = NULL; * }* * * * * break; * p->next = t->next;FileName: hw7_s.c * * * case 4: * free(t);Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return h;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: node *Search(int data, node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); ! node *p=h;Run: ./hw7_s * * * * break; ! while(p!=NULL && data!=p->data)! p = p->next;Date: 2006/1/8 * * * case 6: ! return p;/ * * * * printf("h1°G"); }****************************************************************************** * * * * print_list(h1);/ * * * * printf("h2°G"); int Count(node *h){ * * * * print_list(h2); ! int count=0;#include <stdio.h> * * * * h = Merge(h1, h2); ! while(h!=NULL){ * * * * h1 = h2 = NULL; ! ! count += 1;struct node{ * * * * break; ! ! h = h->next;* int data; * * * case 7: ! }* struct node *next; * * * * if(order) Split(&h, &h1, &h2); ! return count;}; * * * * else{ } * * * * * h = Reverse(h);typedef struct node node; * * * * * Split(&h, &h1, &h2); node *Reverse(node *h){ * * * * } * node *a, *b, *c;void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); * if(h==NULL || h->next==NULL) return h;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); * a = h;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); * b = a->next;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); * c = b->next;£data®√¶^∂«∑s™∫h*/ * * * * break; * a->next = NULL;node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); ! while(c!=NULL){‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); ! ! b->next = a;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } ! ! a = b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } ! ! b = c;node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node)); ! ! c = c->next;list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; ! }void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * b->next = a;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * order = !order;void help(); * return 0; * return b; } }int order=1; void print_list(node *h){ node *Merge(node *h1, node *h2){int main(void){ * node *temp; * node *h, *temp;! node *h1=NULL, *h2=NULL; * temp = h; * h = temp = h1->data < h2->data ? h1 : h2;! while(*h!=NULL){ * while(temp != NULL){ * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); 改回來!! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); * while(h1!=NULL && h2!=NULL){! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next; * * temp = temp->next = h1->data < h2->data ? h1 : h2;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);! ! }else{ * printf("NULLn"); * }! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } ! while(c!=NULL){! ! ! else *h2_ptr = (*h2_ptr)->next = *h; ! ! b->next = a;! ! } node *Insert(int data, node *h){ ! ! a = b;! ! *h = (*h)->next; * node *p, *t, *temp; ! ! b = c;! } * if(h==NULL){ ! ! c = c->next;! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); ! }! *h1_ptr = h1; * * temp->data = data; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! *h2_ptr = h2; * * temp->next = NULL; * return h;! *h = NULL; * * return temp; }* int sel=8, data=0; * }* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; void Split(node **h, node **h1_ptr, node **h2_ptr){* help(); ! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * node *h1=NULL, *h2=NULL;* while(sel){ ! *h1_ptr = h1; * while(*h!=NULL){* * printf("n•ÿ´e™∫Linked list°G"); ! *h2_ptr = h2; * * if((*h)->data%2){* * print_list(h); ! *h = NULL; * * * if(h1==NULL) h1 = *h1_ptr = *h;* * printf("Ω–øÔ拕؇°G"); * t = h->next; * * * else *h1_ptr = (*h1_ptr)->next = *h;* * if(scanf("%d", &sel)==0){ * if(data<p->data){ * * }else{* * * sel=-1; * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;* * * fflush(stdin); * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;* * } * * temp->next = p; * * }* * switch(sel){ * * return temp; * * *h = (*h)->next;* * * case 0: break; * } * }! ! ! case 1: * if(t!=NULL) * (*h1_ptr)->next = (*h2_ptr)->next = NULL;! ! ! ! printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * while(data<p->data || data>t->data){ * *h1_ptr = h1;! ! ! ! if(scanf("%d", &data)==0) continue; * * * p = p->next; * *h2_ptr = h2;! ! ! ! if(order) * * * t = t->next; * *h = NULL;! ! ! ! ! h = Insert(data, h); * * * if(t==NULL) break; }! ! ! ! else{ * * }! ! ! ! ! h = Reverse(h); * temp = (node*)malloc(sizeof(node)); void help(){! ! ! ! ! h = Insert(data, h); * temp->data = data; * printf("0.µ≤ßÙn");! ! ! ! ! h = Reverse(h); * temp->next = p->next; * printf("1.Insertn");! ! ! ! } * p->next = temp; * printf("2.Deleten");! ! ! ! break; ! node *h=NULL, *h1=NULL, *h2=NULL; * printf("3.Searchn");! ! ! case 2: ! help(); * printf("4.Countn");! ! ! ! printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * return h; * printf("5.Reversen");! ! ! ! if(scanf("%d", &data)==0) continue; } * printf("6.Mergen");! ! ! ! if(order) * printf("7.Splitn");! ! ! ! ! h = Delete(data, h); node *Delete(int data, node *h){ * printf("8.helpn");! ! ! ! else{ * node *p, *t; }! ! ! ! ! h = Reverse(h); * if(h==NULL) return h;! ! ! ! ! h = Delete(data, h); * p = h;! ! ! ! ! h = Reverse(h); * t = h->next;! ! ! ! } * if(data == p->data){! ! ! ! break; * * p = p->next;* * * case 3: * * free(h);* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * * return p;* * * * if(scanf("%d", &data)==0) continue; * }* * * * h1 = Search(data, h); * while(data!=t->data){
  • 30. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * return h; data); }/ * * * * print_list(h1);****************************************************************************** * * * * h1 = NULL; node *Search(int data, node *h){* * * * * break; * node *p=h;FileName: hw7_s.c * * * case 4: * while(p!=NULL && data!=p->data)* p = p->next;Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return p;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: int Count(node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); * int count=0;Run: ./hw7_s * * * * break; * while(h!=NULL){Date: 2006/1/8 * * * case 6: * * count += 1;/ * * * * printf("h1°G"); * * h = h->next;****************************************************************************** * * * * print_list(h1); * }/ * * * * printf("h2°G"); * return count; * * * * print_list(h2); }#include <stdio.h> * * * * h = Merge(h1, h2); * * * * h1 = h2 = NULL; node *Reverse(node *h){struct node{ * * * * break; * node *a, *b, *c;* int data; * * * case 7: * if(h==NULL || h->next==NULL) return h;* struct node *next; * * * * if(order) Split(&h, &h1, &h2); * a = h;}; * * * * else{ * b = a->next; * * * * * h = Reverse(h); * c = b->next;typedef struct node node; * * * * * Split(&h, &h1, &h2); * a->next = NULL; * * * * } ! while(c!=NULL){void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); ! ! b->next = a;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); ! ! a = b;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); ! ! b = c;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); ! ! c = c->next;£data®√¶^∂«∑s™∫h*/ * * * * break; ! }node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); * b->next = a;‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); * order = !order;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } * return b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } }node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node));list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; node *Merge(node *h1, node *h2){void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * node *h, *temp;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * h = temp = h1->data < h2->data ? h1 : h2;void help(); * return 0; * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); } * while(h1!=NULL && h2!=NULL){int order=1; * * temp = temp->next = h1->data < h2->data ? h1 : h2; void print_list(node *h){ * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);int main(void){ * node *temp; * }! node *h1=NULL, *h2=NULL; * temp = h; ! while(c!=NULL){! while(*h!=NULL){ * while(temp != NULL){ ! ! b->next = a; 改回來改回來改回來!! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); ! ! a = b;! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next; ! ! b = c;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } ! ! c = c->next;! ! }else{ * printf("NULLn"); ! }! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! ! ! else *h2_ptr = (*h2_ptr)->next = *h; * return h;! ! } node *Insert(int data, node *h){ }! ! *h = (*h)->next; * node *p, *t, *temp;! } * if(h==NULL){ void Split(node **h, node **h1_ptr, node **h2_ptr){! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); * node *h1=NULL, *h2=NULL;! *h1_ptr = h1; * * temp->data = data; * while(*h!=NULL){! *h2_ptr = h2; * * temp->next = NULL; * * if((*h)->data%2){! *h = NULL; * * return temp; * * * if(h1==NULL) h1 = *h1_ptr = *h;* int sel=8, data=0; * } * * * else *h1_ptr = (*h1_ptr)->next = *h;* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; * * }else{* help(); * t = h->next; * * * if(h2==NULL) h2 = *h2_ptr = *h;* while(sel){ * if(data<p->data){ * * * else *h2_ptr = (*h2_ptr)->next = *h;* * printf("n•ÿ´e™∫Linked list°G"); * * temp = (node*)malloc(sizeof(node)); * * }* * print_list(h); * * temp->data = data; * * *h = (*h)->next;* * printf("Ω–øÔ拕؇°G"); * * temp->next = p; * }* * if(scanf("%d", &sel)==0){ * * return temp; * (*h1_ptr)->next = (*h2_ptr)->next = NULL;* * * sel=-1; * } * *h1_ptr = h1;* * * fflush(stdin); * if(t!=NULL) * *h2_ptr = h2;* * } * * while(data<p->data || data>t->data){ * *h = NULL;* * switch(sel){ * * * p = p->next; }* * * case 0: break; * * * t = t->next;* * * case 1: * * * if(t==NULL) break; void help(){* * * * printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * } * printf("0.µ≤ßÙn");* * * * if(scanf("%d", &data)==0) continue; * temp = (node*)malloc(sizeof(node)); * printf("1.Insertn");* * * * if(order) * temp->data = data; * printf("2.Deleten");* * * * * h = Insert(data, h); * temp->next = p->next; * printf("3.Searchn");* * * * else{ * p->next = temp; * printf("4.Countn");* * * * * h = Reverse(h); * return h; * printf("5.Reversen");* * * * * h = Insert(data, h); } * printf("6.Mergen");* * * * * h = Reverse(h); * printf("7.Splitn");* * * * } node *Delete(int data, node *h){ * printf("8.helpn");* * * * break; * node *p, *t; }* * * case 2: * if(h==NULL) return h;* * * * printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * p = h;* * * * if(scanf("%d", &data)==0) continue; * t = h->next;* * * * if(order) * if(data == p->data){* * * * * h = Delete(data, h); * * p = p->next;* * * * else{ * * free(h);* * * * * h = Reverse(h); * * return p;* * * * * h = Delete(data, h); * }* * * * * h = Reverse(h); * while(data!=t->data){* * * * } * * p = p->next;* * * * break; * * t = t->next;* * * case 3: * * if(t==NULL) return h;* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * }* * * * if(scanf("%d", &data)==0) continue; * p->next = t->next;* * * * h1 = Search(data, h); * free(t);
  • 31. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * return h; data); }/ * * * * print_list(h1);****************************************************************************** * * * * h1 = NULL; node *Search(int data, node *h){* * * * * break; * node *p=h;FileName: hw7_s.c * * * case 4: * while(p!=NULL && data!=p->data)* p = p->next;Programmer: CrBoy * * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * return p;Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ °Cn", Count(h)); }Input: * * * * break;Output: the standard out * * * case 5: int Count(node *h){Compilation: gcc hw7_s.c -o hw7_s * * * * h = Reverse(h); * int count=0;Run: ./hw7_s * * * * break; * while(h!=NULL){Date: 2006/1/8 * * * case 6: * * count += 1;/ * * * * printf("h1°G"); * * h = h->next;****************************************************************************** * * * * print_list(h1); * }/ * * * * printf("h2°G"); * return count; * * * * print_list(h2); }#include <stdio.h> * * * * h = Merge(h1, h2); * * * * h1 = h2 = NULL; node *Reverse(node *h){struct node{ * * * * break; * node *a, *b, *c;* int data; * * * case 7: * if(h==NULL || h->next==NULL) return h;* struct node *next; * * * * if(order) Split(&h, &h1, &h2); * a = h;}; * * * * else{ * b = a->next; * * * * * h = Reverse(h); * c = b->next;typedef struct node node; * * * * * Split(&h, &h1, &h2); * a->next = NULL; * * * * } * while(c!=NULL){void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * * * * printf("h1°G"); * * b->next = a;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * * * print_list(h1); * * a = b;°§Jdata®√¶^∂«∑s™∫h*/ * * * * printf("h2°G"); * * b = c;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * * * * print_list(h2); * * c = c->next;£data®√¶^∂«∑s™∫h*/ * * * * break; * }node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß * * * default: printf("±z™∫øȧJ¶≥ª~°In"); * b->next = a;‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * * case 8: help(); * order = !order;int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ * * } * return b;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * } }node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked ! temp = (node*)malloc(sizeof(node));list®√¶^∂«¶X®÷´·™∫™∫head*/ ! temp->data = data; node *Merge(node *h1, node *h2){void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked ! temp->next = p->next; * node *h, *temp;list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ ! p->next = temp; * h = temp = h1->data < h2->data ? h1 : h2;void help(); * return 0; * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); } * while(h1!=NULL && h2!=NULL){int order=1; * * temp = temp->next = h1->data < h2->data ? h1 : h2; void print_list(node *h){ * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);int main(void){ * node *temp; * }! node *h1=NULL, *h2=NULL; * temp = h; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);! while(*h!=NULL){ * while(temp != NULL){ * return h; 統統改回來!! ! if((*h)->data%2){ * * printf("%d -> ", temp->data); }! ! ! if(h1==NULL) h1 = *h1_ptr = *h; * * temp = temp->next;! ! ! else *h1_ptr = (*h1_ptr)->next = *h; * } void Split(node **h, node **h1_ptr, node **h2_ptr){! ! }else{ * printf("NULLn"); * node *h1=NULL, *h2=NULL;! ! ! if(h2==NULL) h2 = *h2_ptr = *h; } * while(*h!=NULL){! ! ! else *h2_ptr = (*h2_ptr)->next = *h; * * if((*h)->data%2){! ! } node *Insert(int data, node *h){ * * * if(h1==NULL) h1 = *h1_ptr = *h;! ! *h = (*h)->next; * node *p, *t, *temp; * * * else *h1_ptr = (*h1_ptr)->next = *h;! } * if(h==NULL){ * * }else{! (*h1_ptr)->next = (*h2_ptr)->next = NULL; * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;! *h1_ptr = h1; * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h;! *h2_ptr = h2; * * temp->next = NULL; * * }! *h = NULL; * * return temp; * * *h = (*h)->next;* int sel=8, data=0; * } * }* node *h=NULL, *h1=NULL, *h2=NULL; * p = h; * (*h1_ptr)->next = (*h2_ptr)->next = NULL;* help(); * t = h->next; * *h1_ptr = h1;* while(sel){ * if(data<p->data){ * *h2_ptr = h2;* * printf("n•ÿ´e™∫Linked list°G"); * * temp = (node*)malloc(sizeof(node)); * *h = NULL;* * print_list(h); * * temp->data = data; }* * printf("Ω–øÔ拕؇°G"); * * temp->next = p;* * if(scanf("%d", &sel)==0){ * * return temp; void help(){* * * sel=-1; * } * printf("0.µ≤ßÙn");* * * fflush(stdin); * if(t!=NULL) * printf("1.Insertn");* * } * * while(data<p->data || data>t->data){ * printf("2.Deleten");* * switch(sel){ * * * p = p->next; * printf("3.Searchn");* * * case 0: break; * * * t = t->next; * printf("4.Countn");* * * case 1: * * * if(t==NULL) break; * printf("5.Reversen");* * * * printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * * } * printf("6.Mergen");* * * * if(scanf("%d", &data)==0) continue; * temp = (node*)malloc(sizeof(node)); * printf("7.Splitn");* * * * if(order) * temp->data = data; * printf("8.helpn");* * * * * h = Insert(data, h); * temp->next = p->next; }* * * * else{ * p->next = temp;* * * * * h = Reverse(h); * return h;* * * * * h = Insert(data, h); }* * * * * h = Reverse(h);* * * * } node *Delete(int data, node *h){* * * * break; * node *p, *t;* * * case 2: * if(h==NULL) return h;* * * * printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * p = h;* * * * if(scanf("%d", &data)==0) continue; * t = h->next;* * * * if(order) * if(data == p->data){* * * * * h = Delete(data, h); * * p = p->next;* * * * else{ * * free(h);* * * * * h = Reverse(h); * * return p;* * * * * h = Delete(data, h); * }* * * * * h = Reverse(h); * while(data!=t->data){* * * * } * * p = p->next;* * * * break; * * t = t->next;* * * case 3: * * if(t==NULL) return h;* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); * }* * * * if(scanf("%d", &data)==0) continue; * p->next = t->next;* * * * h1 = Search(data, h); * free(t);
  • 32. /*¶®•§jæ«∏Í∞T§uµ{æ«®t98Ø≈§AØZ≤¶•…¨u æ«∏π°GF74942294*/ * * * * printf("h2°G"); * node *a, *b, *c; * * * * print_list(h2); * if(h==NULL || h->next==NULL) return h;/ * * * * h = Merge(h1, h2); * a = h;****************************************************************************** * * * * h1 = h2 = NULL; * b = a->next;* * * * * break; * c = b->next;FileName: hw7_s.c * * * case 7: * a->next = NULL;Programmer: CrBoy * * * * if(order) Split(&h, &h1, &h2); * while(c!=NULL){Purpose: ≥–≥y§@≠”singly linked list®√∞ı¶Ê¶U∫ÿ•Ø‡ * * * * else{ * * b->next = a;Input: * * * * * h = Reverse(h); * * a = b;Output: the standard out * * * * * Split(&h, &h1, &h2); * * b = c;Compilation: gcc hw7_s.c -o hw7_s * * * * } * * c = c->next;Run: ./hw7_s * * * * printf("h1°G"); * }Date: 2006/1/8 * * * * print_list(h1); * b->next = a;/ * * * * printf("h2°G"); * order = !order;****************************************************************************** * * * * print_list(h2); * return b;/ * * * * break; } * * * default: printf("±z™∫øȧJ¶≥ª~°In");#include <stdio.h> * * * case 8: help(); node *Merge(node *h1, node *h2){ * * } * node *h, *temp;struct node{ * } * h = temp = h1->data < h2->data ? h1 : h2;* int data; * return 0; * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);* struct node *next; } * while(h1!=NULL && h2!=NULL){}; * * temp = temp->next = h1->data < h2->data ? h1 : h2; void print_list(node *h){ * * h1->data < h2->data ? (h1=h1->next) : (h2=h2->next);typedef struct node node; * node *temp; * } * temp = h; * h2 == NULL ? (temp->next=h1) : (temp->next=h2);void print_list(node*);/*print_list(h); ¶C¶L•Hh∂}¿Y™∫linked list*/ * while(temp != NULL){ * return h;node *Insert(int, node*);/*Insert(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥ * * printf("%d -> ", temp->data); }°§Jdata®√¶^∂«∑s™∫h*/ * * temp = temp->next;node *Delete(int, node*);/*Delete(data, h); ¶b•Hh∂}¿Y™∫linked list§§ßR∞ * } void Split(node **h, node **h1_ptr, node **h2_ptr){£data®√¶^∂«∑s™∫h*/ * printf("NULLn"); * node *h1=NULL, *h2=NULL;node *Search(int, node*);/*Search(data, h); ¶b•Hh∂}¿Y™∫linked list§§¥Mß } * while(*h!=NULL){‰data®√∂«¶^data©“¶b™∫¶Ï∏m*/ * * if((*h)->data%2){int Count(node*);/*Count(h); ≠p∫‚•Hh∂}¿Y™∫linked list§§™∫∏`¬I≠”º∆*/ node *Insert(int data, node *h){ * * * if(h1==NULL) h1 = *h1_ptr = *h;node *Reverse(node*);/*Reverse(h); §œß«±∆¶C•Hh∂}¿Y™∫linked list®√∂«¶^∑s™∫h*/ * node *p, *t, *temp; * * * else *h1_ptr = (*h1_ptr)->next = *h;node *Merge(node*, node*);/*Merge(h1, h2); ¶X®÷h1ªPh2≥o2≠”linked * if(h==NULL){ * * }else{list®√¶^∂«¶X®÷´·™∫™∫head*/ * * temp = (node*)malloc(sizeof(node)); * * * if(h2==NULL) h2 = *h2_ptr = *h;void Split(node**, node**, node**);/*Split(&h, &h1, &h2); §¿≥Œh≥o≠”linked * * temp->data = data; * * * else *h2_ptr = (*h2_ptr)->next = *h; 真的改回來了嗎?list¨∞©_∞∏º∆®√§¿ßO¶s®Ïh1ªPh2§§*/ * * temp->next = NULL; * * }void help(); * * return temp; * * *h = (*h)->next; * } * }int order=1; * p = h; * (*h1_ptr)->next = (*h2_ptr)->next = NULL; * t = h->next; * *h1_ptr = h1;int main(void){ * if(data<p->data){ * *h2_ptr = h2;* int sel=8, data=0; * * temp = (node*)malloc(sizeof(node)); * *h = NULL;* node *h=NULL, *h1=NULL, *h2=NULL; * * temp->data = data; }* help(); * * temp->next = p;* while(sel){ * * return temp; void help(){* * printf("n•ÿ´e™∫Linked list°G"); * } * printf("0.µ≤ßÙn");* * print_list(h); * if(t!=NULL) * printf("1.Insertn");* * printf("Ω–øÔ拕؇°G"); * * while(data<p->data || data>t->data){ * printf("2.Deleten");* * if(scanf("%d", &sel)==0){ * * * p = p->next; * printf("3.Searchn");* * * sel=-1; * * * t = t->next; * printf("4.Countn"); 有沒有哪裡改錯?* * * fflush(stdin); * * * if(t==NULL) break; * printf("5.Reversen");* * } * * } * printf("6.Mergen");* * switch(sel){ * temp = (node*)malloc(sizeof(node)); * printf("7.Splitn");* * * case 0: break; * temp->data = data; * printf("8.helpn");* * * case 1: * temp->next = p->next; }* * * * printf("Ω–øȧJ±˝¥°§J™∫愺∆≠»°G"); * p->next = temp;* * * * if(scanf("%d", &data)==0) continue; * return h;* * * * if(order) }* * * * * h = Insert(data, h);* * * * else{ node *Delete(int data, node *h){* * * * * h = Reverse(h); * node *p, *t;* * * * * h = Insert(data, h); * if(h==NULL) return h;* * * * * h = Reverse(h); * p = h;* * * * } * t = h->next;* * * * break; * if(data == p->data){* * * case 2: * * p = p->next;* * * * printf("Ω–øȧJ±˝ßR∞£™∫愺∆≠»°G"); * * free(h);* * * * if(scanf("%d", &data)==0) continue; * * return p;* * * * if(order) * }* * * * * h = Delete(data, h); * while(data!=t->data){* * * * else{ * * p = p->next;* * * * * h = Reverse(h); * * t = t->next;* * * * * h = Delete(data, h); * * if(t==NULL) return h;* * * * * h = Reverse(h); * }* * * * } * p->next = t->next;* * * * break; * free(t);* * * case 3: * return h;* * * * printf("Ω–øȧJ±˝∑j¥M™∫愺∆≠»°G"); }* * * * if(scanf("%d", &data)==0) continue;* * * * h1 = Search(data, h); node *Search(int data, node *h){* * * * printf("•H%dß@¨∞∞_¬I™∫Linked list°G", * node *p=h;data); * while(p!=NULL && data!=p->data)* p = p->next;* * * * print_list(h1); * return p;* * * * h1 = NULL; }* * * * break;* * * case 4: int Count(node *h){* * * * printf("•ÿ´e™∫Linked list¶@¶≥%d≠”node * int count=0;°Cn", Count(h)); * while(h!=NULL){* * * * break; * * count += 1;* * * case 5: * * h = h->next;* * * * h = Reverse(h); * }* * * * break; * return count;* * * case 6: }* * * * printf("h1°G");* * * * print_list(h1); node *Reverse(node *h){
  • 33. 還有用Excel記錄改了什麼的...
  • 34. ◢▆▅▄▃崩╰( 皿 ╯潰▃▄▅▇◣ 〒 〒)
  • 35. 很多人合作Project的時候
  • 36. 我的比較好! 我比較早寫好!!!!聽我的就對了啦 幹! 哇洗國寶捏!
  • 37. 有時候還會不小心蓋掉別人的
  • 38. 超◢▆▅▄▃崩╰( 皿 ╯潰▃▄▅▇◣ 〒 〒)
  • 39. 程式設計師的美德
  • 40.
  • 41. GITThe Stupid Content Tracker
  • 42. 有好多人在用GitLinux GTK+Android QtCakePHP phpBBDrupal Ruby on RailsGIMP PostgreSQLjQuery Git
  • 43. 什麼是GitThe Stupid Content Tracker 愚蠢的內容追蹤器?時光機器 回到過去 與 平行時空版本控制系統 什麼是版本?怎麼控制?
  • 44. 這就是版本
  • 45. 有八成重複的檔案而且不知道差在哪裡
  • 46. 所以要控制
  • 47. 為什麼要版本控制?記住孩子的成長過程 每次的更新都知道做了什麼改爛程式不用怕可以同時新增不同功能,又不互相影響簡單方便的異地備援 (防意外,還可以防小人)容易合作,改爛程式的人還推不掉責任
  • 48. 不再用檔名說故事
  • 49. 不懂?Let’s Do Git!
  • 50. 先來場激烈的Demo吧!
  • 51. Git起手式git COMMAND [ARGUMENTS]git COMMAND --help #相當實用!!clone - 複製人家的 repositorygit clone git://github.com/git/hello-world.gitinit - 建立新的 repositorygit init
  • 52. 設定Gitconfiggit config -lgit config --global user.name “CrBoy”git config --global user.email “crboy@crboy.net”git config --global color.ui autogit config --global alias.st status~/.gitconfig
  • 53. Git人畜無害四大指令status - 查看目前狀態log - 查看記錄diff - 查看差異show - 查看特定版本
  • 54. Git的版本Repository, Stage (Index), and Working Copy版本號的表示?HEAD, HEAD~, HEAD~~, HEAD^#Branch 名稱
  • 55. 建立新版本add - 將檔案加入 Stage (Index)commit - 將 Stage (Index) 的檔案存入 Repository版本變化越小越好 善用 status 與 diff add -p 好用!!
  • 56. .gitignore忽略它! 忽略它! 忽略它! 忽略它! 忽略它!絕對不需要被納入版本控制的檔案 暫存檔、中間檔、記錄檔 由程式自動產生的檔案大都不需要版本控制.gitignore 這個檔案本身呢?
  • 57. Git時光機器(精華啊!!)checkout - 切換到特定版本branch - 產生分支merge - 融合不同版本
  • 58. 當Git連上網路push - 把自己的東西推送出去pull - 把別人的東西拉回來remote - 遠端相關操作(有很多subcommand)
  • 59. “其他。”reset - 讓 HEAD 回溯到特定版本stash - 暫時存下目前 working copy,回到 HEADcherry-pick - 挑出特定版本的修改來 applyblame - 顯示目前的每一行內容在哪個版本首次出現fetch - 取得遠端內容,但不合併回自己的 repo
  • 60. 看log的好工具git log --graphgitkgiggletigGitX (Mac Only)GitHub.app (Mac Only)
  • 61. 使用Git與別人協作
  • 62. 一些小技巧設定 alias保持 master 為可正常運作版本使用 Github 管理設定檔
  • 63. Git 與 Windows...
  • 64. Git與易經東漢鄭玄〈易論〉:「易一名而含三義:易簡一也;變易二也;不易三也。」簡易 - Git 總是忠實的幫你記錄每個版本的 snapshot變易 - 使用 Git 時,版本間的變化小而快速不易 - 記錄下來的每個版本的內容跟資訊不會被改變
  • 65. Git還有很多東西 but!先會這樣就夠了
  • 66. 對了...
  • 67. 版本控制系統 不是FTP!!
  • 68. 「可不可以把 code 壓縮打包之後上傳到 git?」 『建議千萬不要這樣做,上次有人這樣做,結果...』「結果呢?」 『結果追蹤不了版本,很不方便...』
  • 69. GCC & MAKEGNU C and C++ Compiler Make
  • 70. 那些東西都在幹嘛?
  • 71. 程式碼?執行檔
  • 72. 程式碼編譯組譯連結執行檔
  • 73. 程式碼GCC執行檔
  • 74. 你可能只會....$ gcc -o hw1 hw1.c
  • 75. 你說不定還會....$ gcc -o hw2 main.c a.c b.c
  • 76. 沒那麼簡單
  • 77. 多檔分別編譯$ gcc -c main.c #產生main.o$ gcc -c a.c #產生a.o$ gcc -c b.c #產生b.o$ gcc -o hw2 main.o a.o b.o
  • 78. 看看Preprocessor做了啥? $ gcc -E program.c 可用來了解#include或是#define展開後的結果
  • 79. 想看組合語言? $ gcc -S program.c萬一...我是說萬一...萬一你想看組語的話啦....
  • 80. 有時候非用不可...-I - include (header files) 的搜尋路徑-O - 最佳化程度(0~2)-l - 要 link 的 library-L - library 的搜尋路徑-W* - 關於 warning 的各種設定 推薦使用 -Wall !!
  • 81. 像是這樣編譯....?g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o glwidget.o glwidget.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o main.o main.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o window.o window.cpp 一行一行打???g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o qtlogo.o qtlogo.cpp/usr/bin/moc-qt4 -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I.glwidget.h -o moc_glwidget.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o moc_glwidget.o moc_glwidget.cpp/usr/bin/moc-qt4 -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I.window.h -o moc_window.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o moc_window.o moc_window.cppg++ -o hellogl glwidget.o main.o window.o qtlogo.o moc_glwidget.o moc_window.o -L/usr/lib -L/usr/X11R6/lib -lQtOpenGL -lQtGui -lQtCore -lGLU -lGL -lpthread
  • 82. Make?聰明、靈活、有彈性方便、快速、防手殘
  • 83. Makefile
  • 84. Makefile的基本原則# #開頭的表示它是註解 目標 先 決條件 targets: prerequisites一個 tab字... !元 } recipe 處理方式
  • 85. 簡單的Makefile# 大家好我是註解hw1: hw1.c gcc -o hw1 hw1.c echo “編譯完成”
  • 86. 多檔編譯# 大家好我從剛剛就是註解了main.o: main.c gcc -c main.ca.o: a.c gcc -c a.cb.o: b.c gcc -c b.chw1: main.o a.o b.o gcc -o hw1 main.o a.o b.o
  • 87. 使用變數CC = gccmain.o: main.c $(CC) -c main.ca.o: a.c $(CC) -c a.cb.o: b.c $(CC) -c b.chw1: main.o a.o b.o $(CC) -o hw1 main.o a.o b.o
  • 88. 神祕的符號 - 自動變數CC = gcc pattern rule 第一個prerequisite%.o: %.c $(CC) -c $<hw1: main.o a.o b.o $(CC) -o $@ main.o a.o b.o target
  • 89. 善用變數CC = gccCFLAGS = -Wall -O2OBJS = main.o a.o b.oEXEC = hw1%.o: %.c $(CC) $(CFLAGS) -c $<$(EXEC): $(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS)
  • 90. 從今以後....$ make 一步搞定 !g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o glwidget.o glwidget.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o main.o main.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o window.o window.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o qtlogo.o qtlogo.cpp/usr/bin/moc-qt4 -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. glwidget.h -o moc_glwidget.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o moc_glwidget.o moc_glwidget.cpp/usr/bin/moc-qt4 -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. window.h -o moc_window.cppg++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../shared -I/usr/X11R6/include -I. -o moc_window.o moc_window.cpp......g++ -o hellogl glwidget.o main.o window.o qtlogo.o moc_glwidget.o moc_window.o -L/usr/lib -L/usr/X11R6/lib -lQtOpenGL -lQtGui -lQtCore -lGLU -lGL -lpthread$ _
  • 91. 還是不要 DEMO 吧?
  • 92. 還有個東西叫 CMake...
  • 93. GDBThe GNU Debugger
  • 94. 你用過嗎?
  • 95. Debugger可以幹嘛?
  • 96. Debug!
  • 97. 用printf都怎麼Debug?
  • 98. 印變數內容 +印垃圾文字(AAA, BBB, ...)
  • 99. 查 看變數 印變數內容 + 執行流程印垃圾文字(AAA, BBB, ...) 監控
  • 100. 除此之外你還可以....動態修改變數內容(邊看邊改)動態改變執行流程(邊看邊改)偵測變數被修改的「那個moment」找出程式壞掉的「那個moment」把執行中的程式「抓」過來debug還有那些我也不會的東西
  • 101. Demo 1Segmentation Fault(記憶體區段錯誤)
  • 102. Demo 2動態修改變數值
  • 103. 常用指令run - 開始執行程式 finish - 執行到函式結束break - 設定中斷點 backtrace - 看call stackcontinue - 繼續執行 frame - 切換frameuntil - 執行到特定位置 up / down - 切換framenext - 下一步 print / display - 查看step - 下一步並追進函式 watch - 偵測數值改變
  • 104. 小技巧指令縮寫gdb --tui <C-X> Acommands - 對中斷點自動執行指令
  • 105. 不要再拿printf來debug了!
  • 106. 拜託。
  • 107. PROFILING GNU gprof
  • 108. 使用方式gcc -pg -o program program.c./program # 會產生 gmon.out 檔gprof program # 不是 gprof gmon.out
  • 109. VIMVi IMproved
  • 110. <-- 取消智障型 tab
  • 111. 你覺得怎樣的編輯器才好用?
  • 112. 甚至是....
  • 113. 唉...
  • 114. 每次打字都要先按 i 的編輯器
  • 115. Vim難用死了!!
  • 116. 我學弟的說法...
  • 117. 兩大優點
  • 118. 開起來很快
  • 119. 用起來很快
  • 120. 我也愛用Vim!! (設計對白)
  • 121. For Example....
  • 122. 刪除參數 _node *Merge(node *h1, node *h2){ node *h, *temp; 游標在這 h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 123. 刪除參數 _node *Merge(node *h1, node *h2){ node *h, *temp; → h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 124. 刪除參數node *Merge(node *h1, node _*h2){ node *h, *temp; → h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 125. 刪除參數node *Merge(node *h1, node _ *h2){ node *h, *temp; → h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 126. 刪除參數 _node *Merge(node *h1, node *h2){ node *h, *temp; → h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 127. 刪除參數 _node *Merge(node *h1, node *h2){ node *h, *temp; h = temp = h1->data < h2->data→ h1 : h2; ? h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 128. 刪除參數 _node *Merge(node *h1, node *h2){ node *h, *temp; Backspace h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 129. 刪除參數 _node *Merge(node *h1, node *h){ node *h, *temp; Backspace h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 130. 刪除參數node *Merge(node *h1, node _ ){ node *h, *temp; Backspace h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 131. 刪除參數 _node *Merge(node *h1, no){ node *h, *temp; h = temp = h1->data < Backspace ? h1 : h2; h2->data h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 132. 刪除參數 _node *Merge(node *h1){ node *h, *temp; Backspace h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 133. 刪除參數 _node *Merge(nod){ node *h, *temp; Backspace h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 134. 刪除參數 _node *Merge(){ node *h, *temp; h = temp =Backspace < h2->data ? h1 : h2; h1->data h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 135. 刪除參數 In Vim _node *Merge(node *h1, node *h2){ node *h, *temp; 游標在這 h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 136. 刪除參數 In Vim _node *Merge(node *h1, node *h2){ node *h, *temp; d i ( h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 137. 刪除參數 In Vim _node *Merge(){ node *h, *temp; 完成! h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 138. 往下移5行 _node *Merge(){ node *h, *temp; h = temp = 游標在這 h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 139. 往下移5行 _node *Merge(){ node *h, *temp; ↓ h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 140. 往下移5行node *Merge(){ node *h, _*temp; h = temp = h1->data < h2->data ? h1 : h2; ↓ h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 141. 往下移5行node *Merge(){ node *h, *temp; h = temp _ h1->data < h2->data ? h1 : h2; = h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); ↓ while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 142. 往下移5行node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data _ h2->data ? (h1=h1->next) : (h2=h2->next); < while(h1!=NULL && h2!=NULL){ ↓ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 143. 往下移5行node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); _ while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; ↓ h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 144. 往下移5行node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); 游標在這 } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 145. 往下移5行 In Vim _node *Merge(){ node *h, *temp; h = temp = 游標在這 h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 146. 往下移5行 In Vim _node *Merge(){ node *h, *temp; 5 j h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp = temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 147. 往下移5行 In Vimnode *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); 完成! } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 148. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); 游標在這 } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 149. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); Del } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 150. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_p->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); Del } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 151. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_ext = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); Del } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 152. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_= h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); Del } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 153. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); Del } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 154. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); 刪過頭了 } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 155. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); Ctrl z } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 156. 刪除”temp->next =”node *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); Ctrl z } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 157. 刪除”temp->next =” In Vimnode *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); 游標在這 } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 158. 刪除”temp->next =” In Vimnode *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_temp->next = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); d f = } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 159. 刪除”temp->next =” In Vimnode *Merge(){ node *h, *temp; h = temp = h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next) : (h2=h2->next); while(h1!=NULL && h2!=NULL){ temp =_h1->data < h2->data ? h1 : h2; h1->data < h2->data ? (h1=h1->next):(h2=h2->next); 完成! } h2 == NULL ? (temp->next=h1) : (temp->next=h2); return h;}
  • 160. 學習Vim
  • 161. 第一步:使用它!
  • 162. 設定Vim - .vimrcset numbersyntax onset autoindentset tabstop=4set shiftwidth=4set showcmd
  • 163. Vim移動 (motion)hjkl - 不用背,用身體去記!w, e, b and W, E, B0, ^, $f, F, t, T#G and gg
  • 164. 重複直接說要重複幾次!!例 10j - 向下移動10行 5yy - 複製5行 30x - 刪除30個字元 yy5p - 複製這行並貼上5次
  • 165. 修改內容d - delete (刪除或剪下)y - yank (複製)p - paste (貼上)x, X - 刪除字元r - replace (取代字元)u, <C-r> - Undo, Redo (復原與取消復原)
  • 166. 輸入文字i - inserta - appendo - begin a new linec - changeI, A, O, C
  • 167. 小技巧:kerokerokerokerokero...
  • 168. 搜尋與取代/ - 往前搜尋? - 往回搜尋*, # - 搜尋單字:%s/A/B/g - 把所有的A取代成B 搜尋還不只這樣!!
  • 169. 小技巧:zz 與 z<enter>
  • 170. 小技巧:Vim書籤(mark)
  • 171. 小技巧:<C-N><C-P>自動完成
  • 172. 小技巧:gg=G
  • 173. 重要技巧:help <something>
  • 174. 重要觀念絕對不要全部背下來....
  • 175. Vim文字物件Text Object 文字跟物件有什麼關係?Operator + (i or a) + Region Indicator diw, daw - 刪除一個字(word) di{, da{ d2i{
  • 176. 同時編輯多個檔案spiltvsplittabpage tabnew tabe[dit] gt, gT, #gt
  • 177. Quickfix Window對程式開發者相當實用!!makegrepcopen, cclosecnext, cprevious
  • 178. 程式碼摺疊(Folding)set foldmethod=syntax foldlevel=8zc, zo, za
  • 179. 文字編碼問題Windows上的中文檔案拿到Linux就變亂碼? set fileencodings=utf-8,big5 - 檔案編碼 set encoding=utf-8 - 內部編碼 set termencoding=utf-8 - 終端機編碼每行的結尾有怪怪的東西? set fileformats=unix,dos
  • 180. 自己設定快捷鍵!Key Mapping map nmap imap vmap (還有別的)
  • 181. 外掛程式(Plug-ins)有超級超級多的 Vim 外掛可以用NERDTreeTagbarsnipMateCompletion: neocomplcache, OminCppComplete......
  • 182. Vim也有圖形介面 - GVim
  • 183. Vim很好很強大!! (設計對白)
  • 184. 結語可以不會 vim,但是要挑個好用的編輯器。可以不懂 gcc 跟 make,但是別讓自己編譯到累死。可以不用 gdb,但是要挑個 debugger 來用。可以不選 git,但是一定要有版本控制方案。學習變聰明,不要太努力。
  • 185. 同場加映如果我寫的是其他語言?
  • 186. 適用其他語言的工具Vim、Git 跟 make 是通用的!成熟的語言應該都會有個 Debugger 跟 Profiler C/C++:GDB、GProf PHP:Xdebug Python:PDB JavaScript:Firebug、Chrome Developer Tools
  • 187. Thank You for Your Attension 3Q =) by CrBoy 2 012.07.15...
  • 188. 本簡報由畢玉泉 (CrBoy) <crboy@crboy.net> 製作以創用CC 姓名標示-相同方式分享 3.0 台灣 授權條款釋出歡迎任何形式之重製、散佈與修改,但請明顯標註作者姓名、ID與E-mail,並以相同授權條款將衍生作品釋出簡報中所引用之圖片與商標部分擷取自網際網路,其權利皆分屬各該公司或著作人所有