ç®æãããã°ã©ãã¼ï¼ã«ããããã å½ãµã¤ãã¯ãã¡ãã«å¼ã£è¶ãã¾ããã ãææ°ãããããã¾ãããä¸è¨ãµã¤ãã¸ã移åãã ããã¾ãã
ç®æãããã°ã©ãã¼ï¼ã«ããããã å½ãµã¤ãã¯ãã¡ãã«å¼ã£è¶ãã¾ããã ãææ°ãããããã¾ãããä¸è¨ãµã¤ãã¸ã移åãã ããã¾ãã
ãµã¼ãã¹çµäºã®ãç¥ãã ãã¤ãYahoo! JAPANã®ãµã¼ãã¹ããå©ç¨ããã ãèª ã«ãããã¨ããããã¾ãã ã客æ§ãã¢ã¯ã»ã¹ããããµã¼ãã¹ã¯æ¬æ¥ã¾ã§ã«ãµã¼ãã¹ãçµäºãããã¾ããã ä»å¾ã¨ãYahoo! JAPANã®ãµã¼ãã¹ããæ顧ãã ããã¾ãããããããããé¡ããããã¾ãã
C++ããã¢ã㯠C++è¨èª,STL,sort,ã½ã¼ã,algorithm,ã¢ã«ã´ãªãºã ,使ãæ¹,pred,predicate,ãã¬ãã£ã±ã¼ã,è¿°èª ãã¼ã¸ã®æ«å°¾ã¸ ããããã¼ã¸ã¸ sort(ã½ã¼ã) ãã®ãã¼ã¸ã§ã¯ STL ã®ã¢ã«ã´ãªãºã ã§ãã sort ã®ä½¿ãæ¹ã«ã¤ãã¦è§£èª¬ãã¾ãã åºæ¬çãªä½¿ãæ¹ ä¸¦ã¹æ¿ãã®å¤æåºæºãå¤æ´ãã 大å°é¢ä¿ã®æ¯è¼ã«ã¤ã㦠ãã¬ãã£ã±ã¼ãã®ãã©ã¨ã㣠è±æåææ¸ãèªãã§ãæåæ°ã®é »åº¦é ã«ã½ã¼ãããä¾ èº«é·ãä½éãªã©è¤æ°ã®åºæºã§ã½ã¼ãããä¾ åºæ¬çãªä½¿ãæ¹ ãã¼ã¸ã®å é 㸠sort ã¯ããããã並ã¹æ¿ããè¡ãã¢ã«ã´ãªãºã ã§ãã並ã¹æ¿ãããã¨ãåºæ¥ãã®ã¯ãé常ã®é åããvector ãªã©ã®ã©ã³ãã ã¢ã¯ã»ã¹ã¤ãã¬ã¼ã¿ã使ããã³ã³ããã®ä¸èº«ã¨è¨ããã¨ã«ãªãã¾ããlist ãªã©ã¯ãã©ã³ãã ã¢ã¯ã»ã¹ã§ããªãã®ã§ãã½ã¼ãã§ãã¾ããããlist ã«ã¯ã
ç®æãããã°ã©ãã¼ï¼ã«ããããã å½ãµã¤ãã¯ãã¡ãã«å¼ã£è¶ãã¾ããã ãææ°ãããããã¾ãããä¸è¨ãµã¤ãã¸ã移åãã ããã¾ãã
ï¼ãã®ã³ã³ãã³ãã¯ã¡ã¼ã«ãã¬ã¸ã³ã® STL & iostream å ¥éã«æãå ãããã®ã§ããã STL 㨠iostream ã使ãããã®ãã§ãã¯ãçã¯ã¡ã¼ã«ãã¬ã¸ã³ã®æ¹ã®ãã¼ã¸ãã覧ãã ããï¼ STL ã¯ä¸»ã«æ¬¡ã®ï¼ã¤ããæ§æããã¦ãã¾ããã¢ã«ã´ãªãºã ãé¢æ°ãªãã¸ã§ã¯ããã¤ãã¬ã¼ã¿ã¼ãã³ã³ããããµãã¼ãã¯ã©ã¹ã§ãããã®ä¸ã§æãéè¦ãªã®ããã¢ã«ã´ãªãºã ãã§ããä»ã®ï¼ã¤ã¯ã¢ã«ã´ãªãºã ã®ããã«ãããã¨è¨ã£ã¦ãéè¨ã§ã¯ããã¾ãããã¨ããããã§ã STL ã®ä¸ã§ãã¾ããã®ã¢ã«ã´ãªãºã ããè¦ã¦ãããã¨ã«ãã¾ãã ãã¢ã«ã´ãªãºã ãã¨ããè¨èã¯ãä¸è¬çã«ãç¹å®ã®çµæãæ±ããããã®å¦çæ¹æ³ãã¨ããæå³ã§ä½¿ããã¦ãã¾ãããã¨ãã°ãé åä¸ã®ãã¼ã¿ãã½ã¼ãããããªã©ãã¢ã«ã´ãªãºã ã®ä¸ä¾ã§ãããSTL ã®ã¢ã«ã´ãªãºã ã¯ãåºæ¬çã«ãå¥ç©ãã¨èããæ¹ãåãããããã¨æãã¾ãã使ãããªããããã«ãªãã°ããããã¢ã«ã´ãªãºã
ç®æãããã°ã©ãã¼ï¼ã«ããããã å½ãµã¤ãã¯ãã¡ãã«å¼ã£è¶ãã¾ããã ãææ°ãããããã¾ãããä¸è¨ãµã¤ãã¸ã移åãã ããã¾ãã
ç®æãããã°ã©ãã¼ï¼ã«ããããã å½ãµã¤ãã¯ãã¡ãã«å¼ã£è¶ãã¾ããã ãææ°ãããããã¾ãããä¸è¨ãµã¤ãã¸ã移åãã ããã¾ãã
æ¦è¦ STL (Standard Template Library) ã¨ã¯ãC++ ã®ï¼1998å¹´ã«æ¨æºåãããï¼æ¨æºã©ã¤ãã©ãªã®1ã¤ã§ãã STL ã¯ãtemplate ã¨ããæ©è½ãç¨ããç´äº¤æ§ã®é«ãã©ã¤ãã©ãªã§ãã template templateã¯åããã©ã¡ã¼ã¿ã¨ãã¦ä¸ãããã¨ã§ãä»»æã®åã«å¯¾å¿ããã³ã³ãããã¢ã«ã´ãªãºã ãè¨è¿°ã§ããæ©è½ã§ãã ä¾ãã°ã2ã¤ã®å¤ã®ãã¡å¤§ããã»ããåãåºãé¢æ°max()ãä½ãããã¨ãã¾ããintåã«éå®ãããã®ãªãç°¡åã«ä½ãã¦ä»¥ä¸ã®ããã«ãªãã¾ãã inline int max(int x, int y) { return x > y ? x : y; } ããããdoubleåãæååã«å¯¾ãã¦åããã¨ããããå ´åã æ¹ãã¦doubleåç¨ã®ãã®ã¨æååç¨ã®ãã®ãä½ãå¿ è¦ãããã¾ãã templateãç¨ããã¨ãã®åé¡ã解決ã§ãã¾ãã template
vector00.cppããsourceã // ãµã¤ãºãæå®ãã¦ã¤ã³ã¹ã¿ã³ã¹ã®çæ // vector<int> iVec( N ) ; vector01.cppããsourceã // vectorã®æå¾ã«ã¢ã¤ãã 追å (push_back) // åçé åã®ä½é¨ vector02.cppããsourceã // vectorã®æå¾ã«ã¢ã¤ãã 追å (push_back)ãã¦åé¤(pop_back)ãã¦ã¿ã // åçé åã®å æ¸ãä½é¨ vector03.cppããsourceã // è¦ç´ ã®åç §ã« iterator ã使ç¨ã // STL ã§ã¯ ã³ã³ããã®å 容ãæ±ãéã« iterator ã使ç¨ãã¾ãã vector04.cppããsourceã // vector ã® clear( ) // vectorã®size ã 0 ã«ãªãã¾ãã vector05.cppããsourceã // i
ç®æãããã°ã©ãã¼ï¼ã«ããããã å½ãµã¤ãã¯ãã¡ãã«å¼ã£è¶ãã¾ããã ãææ°ãããããã¾ãããä¸è¨ãµã¤ãã¸ã移åãã ããã¾ãã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}