<div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;">void Swap(int n)</span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;">{</span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> int i,j; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> int temp,temp1;</span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> double temp2; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> for(i=0; i<n-1;i++)</span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> { </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> for(j=i+1; j<n; j++)</span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> {</span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> if(num[4][i] < num[4][j]) </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> { </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> temp=num[0][i]; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> num[0][i]=num[0][j]; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> num[0][j]=temp; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> temp1=num[4][i]; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> num[4][i]=num[4][j]; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> num[4][j]=temp1; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> <span style="font-family:'돋움';"> </span> temp2=avg1[i]; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> avg1[i]=avg1[j]; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> avg1[j]=temp2; </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> } </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> } </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;"> } </span></div> <div style="padding-bottom:0px;line-height:130%;padding-left:6px;padding-right:6px;white-space:pre;padding-top:0px;"><span style="font-family:'돋움';font-size:10pt;">}</span></div> <div class="autosourcing-stub-extra"></div> <div> </div> <div><span style="font-family:'돋움';">전에 짯던 성적표에 swap 부분을 따온건데 이건 잘되는데</span></div> <div> </div> <div><span style="font-family:'돋움';">책에 있던 예제를 풀어보려고</span></div> <div><span style="font-family:'돋움';">void swap(pt pos1, pt pos2)</span><br><span style="font-family:'돋움';">{</span><br><span style="font-family:'돋움';"> pt temp;</span><br><span style="font-family:'돋움';"> temp=pos1;</span><br><span style="font-family:'돋움';"> pos1=pos2;</span><br><span style="font-family:'돋움';"> pos2=temp;</span><br><span style="font-family:'돋움';">}</span></div> <div><span style="font-family:'돋움';">이렇게 짜봣더니 이건 값이 바뀌지않더군요 책에보니 잘못된 예로 이이런식이 써있는걸 보았습니다.</span></div> <div><span style="font-family:'돋움';">근데 첫번째 소스는 변경이 잘만되고 두번째 소스는 왜 되지를 않나요 똑같이 call by referecne 아닌가요?</span></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.