ã¯ããã«
ããã®è¨äºã¯ãã¤ã³ããªæ°ã«ãããã¹ã¬ããã»ã¼ãã¨ã¤ã³ãã«TBBã®ã³ã³ãããã«è¨è¼ããã¦ãã誤ããè¨æ£ãããã¨ãç®çã¨ãã¦ãã¾ããã¤ã³ããªæ°ã®è¨äºã§ã¯ãTBBã³ã³ããã®ç´¹ä»ã«æ³¨æãããã¾ãããã«ãã¹ã¬ããããã°ã©ãã³ã°ã«æ½ãå±éºããã®å±éºãåãé¤ãæ¹æ³ã«ã¤ãã¦ã®è¨è¿°ãæ£ããããã¾ãããæ¬è¨äºã§ã¯ããã«ãã¹ã¬ããããã°ã©ãã³ã°ãå®å ¨ã«è¨è¨ããæ¹æ³ã説æãããã¨ãç®çã¨ãã¾ãã
ãæ¬è¨äºã§ç¨ããã³ã¼ãã¯ãCè¨èªã«é¡ä¼¼ãã¦ãã¾ãããCè¨èªã§ã¯ããã¾ãããæ¯ãèããç解ãã¦ããã ããããããããã®ä»®æ³è¨èªã§ããå®è¡ã§ããç°å¢ã¯ããã¾ããã
ã競åãã¨ããåé¡
ãããã«ã1ã¤ã®ãªã³ã´ãããã¾ããããã¦ã2人ã®äººãããã®ãªã³ã´ã®åã«ãã¾ããããã§2人ã«åãã£ã¦ããªã³ã´ãé£ã¹ã¦è¯ãã§ãããã¨ã ãè¨ãã¨ãã©ããªãã§ããããããäºãã«è²ãåããããããã¯åãåããããã§ããããããã§2人ã仲è¯ããªã³ã´ã«ããã¤ãããã«ã¯ã調åè ããã¦ãã©ã®ããã«åãããã決ãããã¨ãå¿ è¦ã§ãããã¡ããã2人ã®ãã¡ã©ã¡ããã調åè ãå ¼ãã¦ããã¾ãã¾ããã
ã並åããã°ã©ãã³ã°ãè¡ãã¨ãããã¨ã¯ããã®ããã«ã2人以ä¸ã®äººã«ä½ããã®ä½æ¥ãä¾é ¼ãããã¨ã«ãã¨ãããã¾ãããããã®ä½æ¥ãä¾é ¼ããã人ãããããå¥åã®ä½æ¥ãè¡ããªããä½ã®åé¡ãããã¾ãããããããè¤æ°ã®äººãåãè³æºãæä½ãããããªãã¨ãããã¨ãåé¡ãçºçãã¾ãã
ãList1ã¯ã1000åã®æåãæ ¼ç´ã§ããã¹ã¿ãã¯ã§ãã
#define ARRAY_MAX 1000 static char array[ARRAY_MAX]; static int index = 0; int push(char v) { if (index < ARRAY_MAX) { array[index] = v; ++index; } return index; } char pop(void) { if (index > 0) { return array[index]; --index; } return NULL; } int howmany(void) { return index; }
ããã®ã³ã¼ãã¯ãã·ã³ã°ã«ã¹ã¬ããã§å®è¡ãã¦ããéããå®å
¨ã«å®è¡ã§ãã¾ãããããããã«ãã¹ã¬ããã§ã¯ãå®å
¨ã§ã¯ããã¾ããããã«ãã¹ã¬ããã§ã¯ãã³ã¼ããåæã«å®è¡ããã¾ãã次ã®ããã«å®è¡ããªãããã¨ããã©ã®ããã«ãªãã§ããããããªãããããã®å®è¡ç´åã§ãindex
ã¯999ãã¤ã¾ããã¨1ã¤ãªã追å ã§ããç¶æ
ã§ã2ã¤è¿½å ãããã¨ãã¦ããç¶æ³ã§ãã
å®è¡åã® | ã¹ã¬ãã1 | ã¹ã¬ãã2 | å®è¡å¾ã® |
indexå¤ | å®è¡è¡ | å®è¡è¡ | indexå¤ |
999 | int push(char v) { |
999 | |
999 | if (index < ARRAY_MAX) { |
999 | |
999 | array[index] = v; |
int push(char v) { |
999 |
999 | ++index; |
if (index < ARRAY_MAX) { |
1000 |
1000 | return index; |
array[index] = v; |
1000 |
1000 | |
++index; |
1001 |
1001 | |
return index; |
1001 |
ãã¹ã¬ãã2ã®if
æã§index
å¤ãåç
§ããå¾ãã¹ã¬ãã1ã®ã¤ã³ã¯ãªã¡ã³ããå®è¡ãããindex
ã®å¤ã1000ã¨ãªãã¾ãããããã¨ã¹ã¬ãã2ã§ã¯ãarray
é
åã®1001çªç®ã®è¦ç´ ã«ã¢ã¯ã»ã¹ãããã¨ã«ãªãã¾ãããããå®è¡ããçµæã©ããªããã¯ãå®è¡ç°å¢ã«ããç°ãªãã¾ãããã¢ããªã±ã¼ã·ã§ã³ã®ã©ããã§ãæå¾
ããªãã¨ã©ã¼ãåºãå¯è½æ§ãé«ããªãã¾ãã
ããã¦ããã®ã³ã¼ãã®åé¡ã¯ä½ã§ãããããããã¯ãindex
å¤æ°ã®1ã¤ã®ã¤ã³ã¹ã¿ã³ã¹ãè¤æ°ã®ã¹ã¬ããã§å
±æããããã¨ã§ããindex
å¤æ°ãã©ã®ãããªã¢ã¯ã»ã¹ã¹ã³ã¼ããæã£ã¦ãã¦ããé¢ä¿ã¯ããã¾ãããè¤æ°ã®ã¹ã¬ãããåãã¤ã³ã¹ã¿ã³ã¹ãå
±æããã¨ãåé¡ãçºçãã¾ãã
é次å¦çã§çºçãã並ååã¨åãåé¡
ï¼ã並åå¦çã¨ã³ã³ããï¼ã¹ã¬ããã»ã¼ãã¨ã¯ä½ããããï¼
並åããã°ã©ãã³ã°ãè¡ãéã«ã¯ãå¾æ¥ã®é次ããã°ã©ãã³ã°ã§ã¯èããªãã£ããã¨ãèããªãã¦ã¯ãªãã¾ããããã®ãã¡ã®1ã¤ãã並åå¦çã§åæã«ã³ã³ãããæä½ããæã«èµ·ããåé¡ã«ã¤ãã¦ã§ããããã¯ããããã«ãã¹ã¬ããããã°ã©ãã³ã°ã§ã¯ã¹ã¬ããã»ã¼ããªã³ã³ããã使ãå¿ è¦ããããã¨è¡¨ç¾ããã¾ãã
ãã¤ã³ããªæ°ã®ãã®æ¸ãæ¹ã¯ã誤解ãæã表ç¾ãå¤ãå«ãã§ãã¾ãã
1ï¼ã並åããã°ã©ãã³ã°ãã«å¯¾ãã誤解ãä¸ãã
ãã並åããã°ã©ãã³ã°ãè¡ãéã«ã¯ãã¨ãã表è¨ã¨ãããã«ãã¹ã¬ããããã°ã©ãã³ã°ã§ã¯ãã¨ãã表è¨ãæ··å¨ãããã¨ã«ããã並åããã°ã©ãã³ã°ããã«ãã¹ã¬ããããã°ã©ãã³ã°ã«éå®ãããããªè¡¨ç¾ãããã¦ãã¾ããããããã並åããã°ã©ãã³ã°ãã«ã¯ããã«ãã¹ã¬ããã以å¤ã«ãããã«ãã¿ã¹ã¯ããããã¾ãããã£ã¨ããããã«ãã¿ã¹ã¯ãã®å ´åã¯ãããã°ã©ãã³ã°ãã¨ããå°ããªåä½ã§ã¯ãªããã·ã¹ãã ã¨ãã大ããªåä½ã«ãªãã¾ãã
2ï¼å¾æ¥ã®é次ããã°ã©ãã³ã°ã¨ããã»ã©ã並åããã°ã©ãã³ã°ã¯æ°ããããã§ã¯ãªã
ãã並åããã°ã©ãã³ã°ãã«ã¯ãããã«ãã¹ã¬ãããã ãã§ãªãããã«ãã¿ã¹ã¯ããå«ã¾ãã¾ãããã«ãã¿ã¹ã¯ã¯MS-DOSããWindowsã«ç§»è¡ããã¨ããããªãã¡Windows2.0ããçºçãã¦ãããããã¯1987å¹´ã«èªçãã¦ãã¾ãããã ããå®å ¨ãªãã«ãã¿ã¹ã¯OSã«ã¯1993å¹´ã®Windows NT 3.1ã¾ã§å¾ ããªããã°ãªãã¾ãããããããUNIXã«ã¤ãã¦ã¯ãçã¾ããã¨ãããå®å ¨ãªãã«ãã¿ã¹ã¯OSã§ããã
3ï¼ä¸¦åããã°ã©ãã³ã°ã«éã£ãåé¡ã§ã¯ãªã
ãã¹ã¬ããã¯ãªãã£ã«ã«ã®æ ¹æ¬çãªåé¡ã¯ãè¤æ°ã®å¦çãåãã¤ã³ã¹ã¿ã³ã¹ãæä½ãããã¨ã§ããããã¯ã並åããã°ã©ãã³ã°ã«éã£ãåé¡ã§ã¯ããã¾ããããã¼ã¿ãã¼ã¹ãæ±ãå ´åããéåæå®è¡ãè¡ãå ´åãä¸æãã¡ã¤ã«ãã»ããã©ã¨ãã£ãå ±æã¡ã¢ãªãªã©ãæ±ãå ´åãªã©ãé次ããã°ã©ãã³ã°ã§ãã£ã¦ãåæ§ã«çºçãã¾ãã