473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Simple Insertion sort method

Hi, am trying to build an app that uses the insertion sort method to sort numbers entered in a textbox and display them sorted in a label, so i wrote this inside the sort button click event:

Expand|Select|Wrap|Line Numbers
  1. label1.Text = Insertion.insert(textBox1.Text);
and here is the insertion class:

Expand|Select|Wrap|Line Numbers
  1. class Insertion
  2.     {
  3.         public static string insert(string x)
  4.         {
  5.  
  6.             for (int i = 2; i < x.Length; ++i)
  7.             {
  8.                 for (int j = i-1; j > 0 && x[j] < x[i]; --j)
  9.                 {
  10.                     x[j] = x[i];
  11.                 }
  12.             }
  13.             return x.ToString();
  14.         }
  15.     }
Although it looks logical to me, it doesn't work and gives an error: Property or indexer 'string.this[int]' cannot be assigned to -- it is read only.

How to get this workin?
Feb 14 '08 #1
1 1718
Any help?

I tried to use int instead of string, however i don't know how to put string elements inside an array of integers.

Did it this way:

Expand|Select|Wrap|Line Numbers
  1. int[] str = new int[100]; 
  2.  
  3.             for (int k = 0; k < textBox1.Text.Length; k++)
  4.             {
  5.                 string z=textBox1.Text;
  6.  
  7.                 str[k] = textBox1.Text.IndexOf(z,k);  //this should put str[0]=textbox1.text[0] .. and so on
  8.             } 
but it doesn't work.
Feb 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: N. | last post by:
Insertion sort is O(N^2), but I figure I can get it in to O(N log2 N) if the inside loop of the insertion sort is replaced with a binary search. However, I'm having some implimentation problems......
4
by: ashu | last post by:
can anyone tell me that what is the logic of insertion sort. thank you
1
by: Franky, Mondestin | last post by:
Problem description: I have a text file with 700 lines. Each line has 7 elements separated by comma. My text file looks something like : a,b,c,d,e,f,g d,e,h,k,l,m,n x,c,v,f,g,t,z .... and so on...
5
by: Am | last post by:
hi i came to know that microsoft improved the efficiency of quick sort by using a cutoff of 8 elements and continuing with insertion sort then, do anybody have the details about it please...
11
by: Am | last post by:
hi i came to know that microsoft improved the efficiency of quick sort by using a cutoff of 8 elements and continuing with insertion sort then, do anybody have the details about it please...
6
by: Julia | last post by:
I am trying to sort a linked list using insertion sort. I have seen a lot of ways to get around this problem but no time-efficient and space-efficient solution. This is what I have so far: ...
0
by: polocar | last post by:
Hi, I have noticed a strange behaviour of CurrencyManager objects in C# (I use Visual Studio 2005 Professional Edition). Suppose that you have a SQL Server database with 2 tables called "Cities"...
19
by: tkpmep | last post by:
I have an ordered list e.g. x = , and given any positive integer y, I want to determine its appropriate position in the list (i.e the point at which I would have to insert it in order to keep the...
9
by: python_newbie | last post by:
I don't know this list is the right place for newbie questions. I try to implement insertion sort in pyhton. At first code there is no problem. But the second one ( i code it in the same pattern i...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.