⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第3章 排序与查找.txt

📁 我自己整理的c语言教程 来自 c语言之家
💻 TXT
📖 第 1 页 / 共 3 页
字号:
16:           curr =newList();
17:           do
18:           {
19:                appendNode (curr, removeHead (&in));
20:           }
21:         while (in. head && strcmp (curr->tail->u. str,
22:                             in. head->u.str) < = 0);
23:         appendNode(&out, newNode(curr));
24:     }
25:     return Out;
26: }
27:
28: /*
29:  * Merge two sorted lists into a third sorted list,
30:  *.which is then returned.
31:  * /
32: static list_t merge (list_t first, list_t second)
33: {
34:         list_t out;
35:         out.head=out, tail=NULL;
36:
37:         while (first. head && second, head)
38:           {
39:                 listnode_t * temp;
40:                 if (strcmp (first. head->u.str,
41:                        second. head->u.str) <=0)
42:                      appendNode(&out, removeHead(&first));
43:                  else
44:                       appendNode (&out, removeHead (&second));
45:           }
46:         concatList (&out, &first);
47:         concatList (&out, &second);
48:         return out;
49: }
50:
51: /*
52:  * Takes a list of lists 0{ strings and merges'each pair of
53:  * lists into a single list. The resulting list has 1/2 as
54:  * many lists as the original.
55:  * /
56: static list_t mergePairs(list_t in)
57: {
58:      list_ t out;
59:      out. head:out, tail=NUll;
60:
61:      while (in. head)
62:      {
63:           if (in. head->next)
64:           {
65:                  list_t * first =in. head->u.list;
66:                  list_t * second;
67:                              in.head->next->u.list
68:                  in. head->u.list = copyOf (merge ( * first,
69:                                                           * second));
70:                  free (first);
71:                  free (second);
72:                  appendNode (&out, removeHead (&in))
73:                  free (removeHead (&in));
74:             }
75:             else
76:                 appendNode (&out, removeHead (&in));
77:      }
78:      return out
79: }
80:
81: / * Sort strings using merge sort * /
82: void sortStrings (const char * array[])
83: {
84:         int i;
85:         list_t out;
86:         out.head=out, tail=NULL;
87:
88:          for (i=0; array[i]; i++)
89:             appendNode(&out, newNode((void * ) array[i]))
90:          out= split (out);
91:         while (out.head ! =out.tail)
92:             out = mergePairs (out);
93:         if (out.head)
94:                  out = * out.head->u.list;
95:        for (i=O; array[i]; i++)
96:                array[i] = removeHead (&out)->u.str;
97: }










 
 
 
        发表评论  

--------------------------------------------------------------------------------
 
 
相关专题:  

--------------------------------------------------------------------------------
 
 
相关信息: 
 
 没有相关信息 

--------------------------------------------------------------------------------
 
 
相关评论: 
 
 
发表人:guming   发表人邮件:weilaizixing@126.com   发表时间:2004-2-4 14:32:15 
 
haohaoahoa,,wo xi huan  

--------------------------------------------------------------------------------
 
发表人:xzs84   发表人邮件:qdjgx@tom.com   发表时间:2004-2-17 19:54:44 
 
能否具体介绍二分查找法  

--------------------------------------------------------------------------------
 
发表人:tiancai   发表人邮件:lining20092003@yahoo.com.cn   发表时间:2004-5-17 9:55:06 
 
太高深了饿\,我看不懂  

--------------------------------------------------------------------------------
 
发表人:lynn   发表人邮件:lynn0330@tom.com   发表时间:2004-5-20 15:30:14 
 
我觉得程序之间不要过多的说明还好一些:)  

--------------------------------------------------------------------------------
 
发表人:shichuan   发表人邮件:boychenyonghua@hotmail.com   发表时间:2004-6-11 12:03:21 
 
文章中,存在错误。
我现在介绍一下二分查找的简单原理!
注意:二分查找的前提就是内容已经排序了
一组需要排序的内容。我们始终以中间的内容为标准进行查找。 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -