Home > Back-end >  A pointer, bubbling
A pointer, bubbling

Time:10-13

The select function declarations, p=x + I; Is the first address mean?
! Q=x + what I mean, can you help me with normal bubble sort and pointer bubble compare?

#include
# define N 10
Void main ()
{
Int a [10], I, j, t;
Printf (" please enter the number 10: \ n ");
for (i=0; I & lt; N; I++)
The scanf (" % d ", & amp; A [I]);
for (i=0; I & lt; N - 1; I++)
For (j=0; J & lt; N - (I + 1); J++)
If (a [j] & gt; A [m + 1])
{
T=a, [j].
A [j]=a, a + 1 bonus to [j].
A [m + 1]=t;
}
Printf (" from xiao to da order: \ n ");
for (i=0; I & lt; N; I++)
Printf (" % 4 d ", a [I]);
printf("\n");
}

Thank you all!

CodePudding user response:

Is the book that is not a bubble sort, selection sort, and in the form of a pointer, q=x + I, said the q is the current position of x [I]
To the form of a pointer
 void selectsourt (int * x, int n) {
Int I, t, p, q;
for (i=0; i<=n - 1; I++) {
Q=I;
For (p=I + 1; pIf (a [p] <[q] a) q=p;
}
If (q! I)={t=a [q]; A [q]=a, [p]. A [p]=t; }
}
}

In contrast to understand yourself

CodePudding user response:

reference 1st floor qybao response:
the book that is not a bubble sort, selection sort, and in the form of a pointer, the q q=x + I, said the current x [I] is the location of the
To the form of a pointer
 void selectsourt (int * x, int n) {
Int I, t, p, q;
for (i=0; i<=n - 1; I++) {
Q=I;
For (p=I + 1; pIf (a [p] <[q] a) q=p;
}
If (q! I)={t=a [q]; A [q]=a, [p]. A [p]=t; }
}
}

Contrast to understand yourself


The above change a x

 void selectsourt (int * x, int n) {
Int I, t, p, q;
for (i=0; i<=n - 1; I++) {
Q=I;
For (p=I + 1; pIf (x [p] <[q]) x q=p;
}
If (q! I)={t=x [q]; [q]=x x [p]. X [p]=t; }
}
}

CodePudding user response:

refer to the second floor qybao response:
Quote: refer to 1st floor qybao response:

Is the book that is not a bubble sort, selection sort, and in the form of a pointer, q=x + I, said the q is the current position of x [I]
To the form of a pointer
 void selectsourt (int * x, int n) {
Int I, t, p, q;
for (i=0; i<=n - 1; I++) {
Q=I;
For (p=I + 1; pIf (a [p] <[q] a) q=p;
}
If (q! I)={t=a [q]; A [q]=a, [p]. A [p]=t; }
}
}

Contrast to understand yourself


The above change a x

 void selectsourt (int * x, int n) {
Int I, t, p, q;
for (i=0; i<=n - 1; I++) {
Q=I;
For (p=I + 1; pIf (x [p] <[q]) x q=p;
}
If (q! I)={t=x [q]; [q]=x x [p]. X [p]=t; }
}
}


I have a question, q!=I, how to understand

CodePudding user response:

q!=I, the if (x [p] <[q]) x q=p; Here than I ever find position smaller elements, so q changed
On the other hand, if the q==I show smaller elements than I didn't find position, so p did not change, p will keep the position of the I

CodePudding user response:

Day! I am now on qq!=I, the understanding is still confused about

CodePudding user response:

Start cycle number, only 9 I is one of the nine digits said is good size, and then the tenth position and I represent several more size, so understand?

CodePudding user response:

refer to 6th floor weixin_46360087 response:
start cycle number, only 9 I is one of the nine digits said is good size, and then the tenth position and I represent several more size, so understand?

Is this meaning
for (i=0; i<=n - 1; I++) {//I start from the first element
Q=I;//record to compare current position
For (p=I + 1; pIf (x [p] <[q]) x q=p;//if a location is smaller than p position, the change of p
for the position}
If (q! I)={t=x [q]; [q]=x x [p]. X [p]=t; }//if p is not equal to I, shows that there is more than I small elements, the exchange of even the position of the element
}

Your hand animation had a figure
Such as an array of 15324
I loop in the first round, I=0, p=I, x p=0=1, the location of the j since I + 1 began to turn and x p=0=1 comparison, found 5324 smaller than p position, so p did not change, so p and I are the same, no exchange, so after I loop in the first round of the results of 15324

Second I cycle, I=1, p=I, x [p=1]=5, j is with I + 1 x [j=2] start cycle, (x=3) [j=2] than (x=5) [p=1] is small, so the p instead of 2 (x=3) [p=2], continue to j loop (x [j=3]=2) than (x=3) [p=2] is small, the p to 3 (i.e., x [p=3]=2), continue to j loop, [j]=4 (x=4) than (x [p=3]=2), so don't change p, j loop ends, at this point p is 3, (p=3).=(I=1), so the exchange] [I=1=5 x and x [p=3]=2 two elements, after the second round I loop so a result of 12354

So on behind

CodePudding user response:

Are called selection is to choose a smaller number than the current loop I position, remember its location p, such as the example above x [I=1] is 5, small number is 2 more than the location, with records of where it is 3 p, namely x [p=3]=2, so judge p and I, just know to have chosen than smaller number, I if there is no (i.e. p==I, because I cycle start initialization p=I), is doing nothing, continue to the next time I loop; If you have, is the exchange of p position location and the I element,

CodePudding user response:

The easiest way to understand is the smallest in the array of selected in the first place, the second youngest elected came in second, third, the smallest number of choice for finished third, and so on, know the last a minimum number of rows in the end, can finish the whole process of ordering

CodePudding user response:

references 9 f qybao response:
the easiest way to understand is the smallest in the array of selected in the first place, the second youngest elected came in second, third, the smallest number of choice for finished third, and so on, know the last a minimum number of rows in the end, can finish the whole process of ordering

Ok, understand, speak very detailed, thank you very much

CodePudding user response:

refer to 7th floor qybao response:
Quote: refer to the sixth floor weixin_46360087 response:

Start cycle number, only 9 I is one of the nine digits said is good size, and then the tenth position and I represent several more size, so understand?

Is this meaning
for (i=0; i<=n - 1; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull