reverse

Reverse the string in C++

柔情痞子 提交于 2019-12-06 13:37:56
#include <iostream> #include <cstdlib> using namespace std; main() { beginning: string name; cout << "Hey! Enter your name" << endl; cin >> name; int i = name.length() - 1; do { cout << name[i]; i--; } while (i > -1); cout << " Your reverse name is " << name[i] << endl; cout << name[i] << " Your reverse name is " << endl; goto beginning; } Why the "zsuidakrA" is being displayed before "Your reverse name is" although I have coded like cout<<" Your reverse name is "<<name[i]<<endl; For cout<<name[i]<<" Your reverse name is "<<endl; this line, I have found only "Your reverse name is" but there is

Need a program to reverse the words in a string

时间秒杀一切 提交于 2019-12-06 13:01:01
问题 I asked this question in a few interviews. I want to know from the Stackoverflow readers as to what should be the answer to this question. Such a seemingly simple question, but has been interpreted quite a few different ways. 回答1: if your definition of a "word" is a series of non-whitespace characters surrounded by a whitespace character, then in 5 second pseudocode you do: var words = split(inputString, " ") var reverse = new array var count = words.count -1 var i = 0 while count != 0

Reversing an array in assembly

蓝咒 提交于 2019-12-06 11:26:52
I'm trying to figure out how to reverse an array in assembly in a way that makes it as flexible as possible. The code I have so far is this: ; This program takes an integer array and reverses it's elements, using a loop, the SIZE, TYPE and LENGTHOF ; operators. TITLE lab4 (lab4.asm) INCLUDE Irvine32.inc .data arr DWORD 1h, 2h, 3h, 4h, 5h, 6h ; Array of integers with 6 elements. len DWORD LENGTHOF arr / 2 ; The length of the array divided by 2. ;rng DWORD LENGTHOF arr ; The complete length of the array. .code main PROC mov eax, len ; Moves the length (divided by 2) into the eax register. mov

Read binary file backwards using Java

喜你入骨 提交于 2019-12-06 07:39:10
I'm reading in binary files normally using: //What I use to read in the file normally int hexIn; for(int i = 0; (hexIn = in.read()) != -1; i++){ } What I need to do is read the file in backwards I have tried something along the lines of... but it does not work! I have looked a loads of help pages but can't find anything I hope you can help me please. //How im trying to read in the file backwards for(long i = 0, j = length - 1; i < length; i++, j--){ int hexIn = 0; hexIn = in.read(); } Just to complacate things I'm reading the binary in and converting it to hex using //This makes sure it does

Lisp Reverse “all” Function

折月煮酒 提交于 2019-12-06 05:46:19
I want to write a function in lisp that reverses all elements from the list using map functions but I don't have any idea how to start this.. I think I have to use the built in reverse function somehow.. For example if I have the list (1 2 3 (4 5 6 (7 8 9))) I would get (((9 8 7) 6 5 4) 3 2 1) or if I had the list(1 2 3 (4 5) (6 7)) I would get ((7 6) (5 4) 3 2 1) .. Any help is appreciated! Just a quick answer, not sure about efficiency/elegancy: (defun reverse-deeply (list) (mapcar #'(lambda (li) (cond ((consp li) (reverse-deeply li)) (t li))) (reverse list))) (defun reverse-list (list) (let

Reverse doubly-link list in C++

杀马特。学长 韩版系。学妹 提交于 2019-12-06 01:53:09
I've been trying to figure out how to reverse the order of a doubly-linked list, but for some reason, in my function void reverse() runs while loop once and then crashes for some reason. To answer some questions ahead, I'm self-teaching myself with my brothers help. This isn't all of the code, but I have a display() function which prints all nodes chronologically from start_ptr and a switch which activates certain functions like case 1 : add_end(); break; case 2 : add_begin(); break; case 3 : add_index(); break; case 4 : del_end(); break; case 5 : del_begin(); break; case 6 : reverse(); break;

Objective-c/IOS: What's the simplest way to play an audio file backwards

回眸只為那壹抹淺笑 提交于 2019-12-06 01:38:41
问题 I've been struggling with this one for quite a while now, and there are no code examples of it being done on the net. Can anyone help me? My app uses AVFoundation to record the audio. @16 bit depth , 2 channels , WAV I can access the bytes of the audio, I just don't know how to reverse it. 回答1: In wave data samples are interleaved. This means the data is organised like this. Sample 1 Left | Sample 1 Right | Sample 2 Left | Sample 2 right ... Sample n Left | Sample n right As each sample is 16

Reverse proxy capable pure python webserver?

拟墨画扇 提交于 2019-12-05 22:13:59
I am looking for a pure python based web server has the capability for reverse proxy as well? wr. Have a look at Twisted , especially its ReverseProxyResource . Twisted Web also provides various facilities for being set up behind a reverse-proxy, which is the suggested mechanism to integrate your Twisted application with an existing site. http://pypi.python.org/pypi/proxylet/ From http://www.rfk.id.au/blog/entry/proxylet-lightweight-HTTP-reverse-proxy proxylet is a lightweight reverse proxy for HTTP with nonblocking IO courtesy of eventlet. Looks like source is available as well. I've never

How can I animate the opposite way?

非 Y 不嫁゛ 提交于 2019-12-05 22:05:35
Greetings, I am changing the width of an element which serves as a bar , and that works. However I can't make it so that it animates it in the opposite direction. I tried putting - in front of bar_width but to no avail. Width will be dynamically calculated it's just that I want the direction to go to the left rather than to the right like so <------- not -----------> var bar_width=$(this).css('width') ; $(this).css('width', '0').animate({ width: bar_width }, queue:false,duration:3500,easing: easing}); You could animate it from right to left by animating both the margin-left and width of the

Reversing a Number using bitwise shift

China☆狼群 提交于 2019-12-05 19:17:49
I am trying to find a way to reverse a number without Converting it to a string to find the length Reversing the string and parsing it back Running a separate loop to compute the Length i am currently doing it this way public static int getReverse(int num){ int revnum =0; for( int i = Integer.toString(num).length() - 1 ; num>0 ; i-- ){ revnum += num % 10 * Math.pow( 10 , i ); num /= 10; } return revnum; } But I would Like to implement the above 3 conditions. I am looking for a way , possibly using the bit wise shift operators or some other kind of bitwise operation. Is it possible ? If so how