Swap nodes in a singly-linked list

Why Infinite loop? Infinite loop is because of self loop in your list after calling swap() function. In swap() code following statement is buggy. (*b)->next = (temp1)->next; Why?: Because after the assignment statement in swap() function temp1‘s next starts pointing to b node. And node[b]‘s next point to itself in a loop. And the self … Read more

Replace Div with another Div

You can use .replaceWith() $(function() { $(“.region”).click(function(e) { e.preventDefault(); var content = $(this).html(); $(‘#map’).replaceWith(‘<div class=”region”>’ + content + ‘</div>’); }); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <div id=”map”> <div class=”region”><a href=”link1″>region1</a></div> <div class=”region”><a href=”link2″>region2</a></div> <div class=”region”><a href=”link3″>region3</a></div> </div>

Swap two items in List

Check the answer from Marc from C#: Good/best implementation of Swap method. public static void Swap<T>(IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; } which can be linq-i-fied like public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = … Read more

How does the standard library implement std::swap?

How is std::swap implemented? Yes, the implementation presented in the question is the classic C++03 one. A more modern (C++11) implementation of std::swap looks like this: template<typename T> void swap(T& t1, T& t2) { T temp = std::move(t1); // or T temp(std::move(t1)); t1 = std::move(t2); t2 = std::move(temp); } This is an improvement over the … Read more

How to find out which processes are using swap space in Linux?

The best script I found is on this page : http://northernmost.org/blog/find-out-what-is-using-your-swap/ Here’s one variant of the script and no root needed: #!/bin/bash # Get current swap usage for all running processes # Erik Ljungstrom 27/05/2011 # Modified by Mikko Rantalainen 2012-08-09 # Pipe the output to “sort -nk3” to get sorted output # Modified by … Read more