这两个函数用于在使用函数执行选择排序时使用指针交换变量selectionSort(int *,int).但是在排序之后,数组的一些元素变为零.
void selectionSort(int *x,int len){
int i,j,max;
for(i=len-1;i>=0;i--){
max = 0;
for(j=1;j<=i;j++){
if(x[j]>x[max]){
max = j;
}
}
swap(x+max,x+i);
}
}
void swap(int *a,int *b){
//This one works perfectly
int temp;
temp=*b;
*b=*a;
*a=temp;
}
void swap(int *a,int *b){
//This one gives unexpected results
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}
Run Code Online (Sandbox Code Playgroud) 这是给 php 警告
<?php
$xml = simplexml_load_file("videos.xml") or die("Error: Object creation
Failed");
$videos = array();
foreach( $xml->children() as $video){
$a= $video->Serial;
$b=$video->URI;
$videos[$a] = $b;
}
header('Content-type: application/json');
echo json_encode($videos);
?>
Run Code Online (Sandbox Code Playgroud)
第 8 行中的非法偏移类型。如何修复?