Reversing single linked list in C#

That question gets asked a lot. When I was asked it in my interviews many years ago, I reasoned as follows: a singly-linked list is essentially a stack. Reversing a linked list is therefore a trivial operation on stacks: newList = emptyList; while(!oldList.IsEmpty()) newList.Push(oldList.Pop()); Now all you have to do is implement IsEmpty and Push … Read more

Reversed cumulative sum of a column in pandas.DataFrame

Reverse column A, take the cumsum, then reverse again: df[‘C’] = df.loc[::-1, ‘A’].cumsum()[::-1] import pandas as pd df = pd.DataFrame( {‘A’: [False, True, False, False, False, True, False, True], ‘B’: [0.03771, 0.315414, 0.33248, 0.445505, 0.580156, 0.741551, 0.796944, 0.817563],}, index=[6, 2, 4, 7, 3, 1, 5, 0]) df[‘C’] = df.loc[::-1, ‘A’].cumsum()[::-1] print(df) yields A B C … Read more

http_sub_module / sub_filter of nginx and reverse proxy not working

Check if the upstream source has gzip turned on, if so you need proxy_set_header Accept-Encoding “”; so the whole thing would be something like location / { proxy_set_header Accept-Encoding “”; proxy_pass http://upstream.site/; sub_filter_types text/css; sub_filter_once off; sub_filter .upstream.site special.our.domain; } Check these links https://www.ruby-forum.com/topic/178781 https://forum.nginx.org/read.php?2,226323,226323 http://www.serverphorums.com/read.php?5,542078

How do you reverse a string in-place?

As long as you’re dealing with simple ASCII characters, and you’re happy to use built-in functions, this will work: function reverse(s){ return s.split(“”).reverse().join(“”); } If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny. You might want … Read more

Why there is two completely different version of Reverse for List and IEnumerable?

It is worth noting that the list method is a lot older than the extension method. The naming was likely kept the same as Reverse seems more succinct than BackwardsIterator. If you want to bypass the list version and go to the extension method, you need to treat the list like an IEnumerable<T>: var numbers … Read more