You got it sir - great job.
Kevin Bewley
Posts
-
CCC 13-7-2023 -
CCC 13-7-2023Thanks for the encouragement, I wasn't sure where to pitch it. So I went for "fun" :)
-
Oi Kevin Bewley !Sorry - in a meeting - done now. Enjoy it :-)
-
CCC 13-7-2023Ring of fire from abnormal pieces, about fifty (7)
-
CCC 12-07-2023GLANCE Definition: Look A key - musical key of G Run through - to Lance
-
Coding - so what's a crime and whats a misdemeanor?I often get accused of commenting the obvious but I was taught to, and still do for complex algorithms/methods write what I want to do in terms of words as a comment (my intended function). Then I write the code underneath. The comments were there before the code, so it'd take me more time to delete them. Sorry - if you find it hard to just scroll past that stuff...
-
Nerd question of the dayI recall that the Bistromathic Drive[^] in the ship owned by Slartibartfast was faster than the heart of gold. Indeed, I'm sure the IID is referred to as an electric pram!
-
Have I implemented this well - code critique & tips please?Okay, so I'm a self-taught programmer and have been brushing up on all the 'boring' bits that CS students do that most of us self-taught ignore. Things like Algorithms and Data Structures (particularly). So I found a nice exercise book that explains how algorithms work, but then leaves the implementation to the reader. This works well for me as I'm the kind of person for whom knowledge 'sticks' better if I can "figure it out for myself". So, I've just finished the Chapter on Sorting and quite easily managed to implement working Bubble Sort, Radix Sort, Mergesort etc. I really struggled getting Quicksort to work though - lots of out of bounds errors that I found hard to track down. So, now I do have it working - I'm wondering whether I just set about coding the algorithm (I'm using C#) the wrong way in the first place. So, my question, I'll post my code below, and I'd really appreciate it if you guys could tell me (mentor style I guess) how I could have done a better job if I did it again. What I don't want is a long discussion of "you chose a silly pivot value", remember I implemented this from an exercise and that told me explicitly to use the left-most value of each sub-array as the pivot for each partition. So, here's the code that basically creates the object and calls the sort method:
class Program { public static void Main(string\[\] args) { Console.WriteLine("Exercise 24.10 - Quicksort\\n\\n"); Quicksort sort = new Quicksort(12); Console.WriteLine("Unsorted: {0}\\n", sort); sort.Sort(); Console.WriteLine("\\n Sorted: " + sort); Console.Write("\\nPress any key to continue . . . "); Console.ReadKey(true); } }
and here's the object that implements the Quicksort & the partitioning:
class Quicksort
{
private int[] data;
private Random rng = new Random();public Quicksort(int size) { data = new int\[size\]; //Test Data from TextBook: //data = new int\[\] {37, 2, 6, 4, 89, 8, 10, 12, 68, 45}; // Generate some Random Data for(int i=0; i<data.Length;i++) data\[i\]=rng.Next(0,100); } // end constructor public void Sort() { // Calls the 'private' recursive Quicksort method recSort(0, data.Length-1); } private void recSort(int left, int right) { // Recursively calls itself until the pointers collide // And as the partitioning works in-place there's no // writing at the end, the array is already sorted if(left<ri
-
Plumbing Help -> This seems the right placeGo with the plastic (Hep2O) fittings and pipework from a NAMED BRAND. In my experience the quality, sealing ability and longevity are as good as copper. In fact, my water company is replacing all its 'under tarmac' pipework with plastic. Also, plastic has more give and is therefore more frost resistant. Tip though: Don't be tempted to cut the plastic pipe to length with a hacksaw/jr hacksaw - use the PROPER tool for cutting plastic pipe. Most times I've seen the fittings fail it's because of a 'rough' hacksawn pipeend going into a fitting rather than the right-angled sharp cut from the proper tool. http://www.hep2o.com/[^]
-
listviewIf I'm interpreting your question right you want the user to be able to select all of the items in the ListView, but you don't want to give them a button to do it? If so, why not set up a context menu with a Select All option? Then, as others have suggested, step through all the items in the LV and set Checked = true; for each item.
-
C# Using random FunctionSounds like homework to me but here's a couple of clues:
// Instantiate a Random number generator
Random myRandom = new Random();// Get a random number between 0 and 100
int randomNumber = myRandom.Next(101);Now, how could I take my randomNumber and select a colour based on that value..? Perhaps you could do a little research into system.drawing.color? Then I need to do something like the code below to change the background colour... this.BackColor = System.Drawing.Color.Red;
-
Maths for bouncing a ball around a window..I think I might have found my own answers here actually. I'll have a play around and see what I come up with. But you were on the right track with what you said. Modify the DeltaY by adding a constant gravity component each iteration. I guess I could also add a 'friction' component acting in the -Y and -X directions each iteration to have the ball slow due to air resistance too. Hmmm! This could be a fun experiment...
-
Maths for bouncing a ball around a window..So you didn't attempt to model gravity in the motion of your ball? Effectively your ball was in outer space? :-)
-
Maths for bouncing a ball around a window..Hi all I'm playing around with threading at the moment (self-directed learning) and what I would like to do is bounce balls around in a windows each with a thread of their own. I know this might not be the BEST way to do this, I want to do it purely for the learning. My idea is that I'll have a ball object that will be updated by a timer Event. At regular intervals, on a separate thread, I'll get the positions off all my balls and Draw them to the window. I will probably attempt to get some collision detection between balls going eventually but for now, they'll just bounce if they hit the sides/top of the window. Anyway, what I really would like to do is have the balls move around with fairly good physics. ie. gravity. But, my maths although good is inappropriate (I did maths & statistics at A level for my current career in biology). So, what equations can I use to give me x and y coordinates when I plug in an increasing value for time(t)? I realise I'll need to check if for x+radius>=rightWallX and x-radius<=leftWallX etc. it's just the movement in the presence of gravity I need. Can anyone help me out with the maths? I did try google but I think I'm failing to provide the 'right' search terms to find what I want.
-
Want to find a blog host (C#.NET) that will allow my readers to download code & executablesDoes the free hosted version allow you to have files for download for your readers?
-
Want to find a blog host (C#.NET) that will allow my readers to download code & executablesHmmm, can't find how to edit my blog on my profile. Only how to sign up for other blogs or to make an article, I don't want to do either. What I want to do is document my own coding experiences with a little code/some downloads to illustrate the journey.
-
Want to find a blog host (C#.NET) that will allow my readers to download code & executablesperfect answer! although now I feel a little dumb.. ah well!
-
Want to find a blog host (C#.NET) that will allow my readers to download code & executablesI don't want to host it myself, looking for a site where I can just sign up and start blogging. Uploading my files as necessary. Any suggestions folks? Cheers, Kev
-
Incrementing and Decrementing - Just Trying to UnderstandI know - BUT, why the hell would anyone write such a monstrosity. ;P Also, as it was clearly a beginner question, I was trying to simplify. So you get 10/10 for correctness but 2/10 for being clear for the sake of the OP.. :omg:
-
Incrementing and Decrementing - Just Trying to UnderstandThis line is the important one: int z = y-- + x; it says to the computer, assign y + x into a variable called z. When you've done that knock one off the stored value of y. so, in the line int z = y-- + x; z gets assigned with 100 + 10 (110) then y gets reduced to 99. In the line z = --z + x; The operation goes; knock one off z then assign the sum of z + x to z. ie. take 1 off 110(z) to get 109; THEN assign 109+10 to z. Basically if the ++ or -- is BEFORE the variable name (--y) then the operation is done BEFORE the rest of the line. But, if the ++ or -- is AFTER the variable name, the operation is done AFTER the rest of the line. Simples! :-)