-
Strings? It's simple, you don't need to stack, you can swap heads and tails, and keep going to the middle until you meet.
#include
Invert the string.
Enter as the string str;
Returns the address of the string.
char* reverse(char *str)int i,n;
char tmp;
if (str == null)
return 0;
n=strlen(str)-1;
for(i=0;itmp = str[i];
str[i] = str[n];
str[n] = tmp;
return str;
-
It's not easy to change.
See a stack that pushes everything in, and then takes it out.
-
Taking python as an example, the example of outputting an array in reverse order is:
#!/usr/bin/env python
# -*coding: utf-8 -*
arg = 1, 2, 3, 4, 5]
arg_1 =
for i in range(1, len(arg) +1):
print arg
print arg_1
Execute the program, and the output result is:
From the results, you can see that the array is output in reverse order.
-
Taking python as an example, the example of outputting an array in reverse order is:
#!/usr/bin/env python
# -*coding: utf-8 -*
arg = 1, 2, 3, 4, 5]
arg_1 =
for i in range(1, len(arg) +1):
print arg
print arg_1
Execute the program, and the output result is:
From the results, you can see that the array is output in reverse order.
-
From the last element, backward iterate to the 0 elements of the array, and output them one by one.
1. Create an array;
2. Enter the value;
3. Traverse the output array in reverse order.
**:int main()
-
There was something upstairs that I thought was a problem, and I changed it.
#include
void main(void)
Let's say it's your array.
int i = 10;
while(i > 0)
-
#includeintmain()return0;Analysis: First, the input is an integer, so the first digit is not zero, so we can write it with the remainder of dividing by 10. a=num%10 is the last digit of the output number, then divide by 10 and eliminate the last digit of the number, so that the penultimate digit of the number will be output.
And so on, the numbers can be output in reverse order.
Extended material: Define n-level permutations.
Definition 1 is ,.. by the natural numbers 1,2An ordered array of n is called an n-order permutation (referred to as permutations for short).
For example, 2431 is a four-level permutation and 45321 is a five-level permutation.
Note: The total number of n-level permutations is:
Obviously, 1,2 ,..n is also an n-level arrangement, which has a natural order, that is, it is arranged in an increasing order; All other permutations disrupt the natural order to a greater or lesser extent.
Reverse Order Definition2 In an arrangement, a pair of numbers is said to be in reverse order if the position of the front and back is opposite to the order of magnitude, i.e., the number that precedes it is greater than the number that follows. [1]
Note: 1For n different elements, there is a "standard order" between the elements (for example, n different natural numbers can be specified as the standard order from small to large), so in any arrangement of these n elements, when the order of some two elements is different from the standard order, there is 1 "reverse order".
2.The total number of all inverse orders in a permutation is called the inverse number of the permutation.
3.Permutations with odd inverse ordinal numbers are called odd permutations, and permutations with even inverse ordinal numbers are called even permutations.
-
There was something upstairs that I thought was a problem, and I changed it.
#include
void main(void)
Let's say it's your array.
int i = 10;
while(i > 0) }
I originally wanted to use it, but I found it a little difficult to fight together in the end; >>>More
Let's talk about the idea first:
Get the last one within this string. location, which is the index. >>>More
The meaning of the title is said upstairs.,Here's a **.。 >>>More
It's the same you, but there is a difference in itself between having wisdom and not having wisdom, and the result is different. >>>More