|
I am probably misunderstanding your question, but any implementation of a List (ArrayList, LinkedList etc) should expose a Count property, and so your question of how to display this is down to where you want to display it.
on the console:
Console.WriteLine(myList.Count);
in a messageBox
MessageBox.Show(miList.Count.ToString());
sorry if ive misunderstood
|
|
|
|
|
This is not a C# question but an algorithm question for my homework at university.
|
|
|
|
|
Perhaps you should do you own homework? You learn a lot more that way. This isn't a difficult question.
|
|
|
|
|
It is absolutely sure that I can not do that, although I have tried very much. Any idea?
|
|
|
|
|
What have you tried? Show people that you are thinking about this and not just too lazy to do your homework and you'll find people are much more responsive.
You need to write a recursive function, something like this (you fill in the blanks):
<code>
public int CountNodes(Node n)
{
if(ExitCondition)
{
return ?;
case?
}
else
{
return ? + CountNodes(?);
}
}
</code>
|
|
|
|
|
while I Agree with wjousts assertion that a) this is not a particularly difficult question and b) you should do your own homework - I will provide some assistance.
You must know what a linked list is, if not go back and refer to your course notes. Recursion you probably also know about - essentially calling a function from itself (or put another way "to understand recursion, you must first understand recursion /geekhumour)
So, to help write this algorithm, I find it easy to start off in pseudo-code
while {not at end of list)
Incrememnt counter
loop
return counter
Now, I know you super-highlight-stressed that you want it DISPLAYED and not RETURNED!!11 (your homework said display it right?) however in order to dispaly something...it must first be returned from somewhere.
Turning the above into a "recursive function" is the bit you've got to do. If this is not enough to get you going on your homework, then seriously consider whether you should be studying a subject you cannot do!
Good luck.
|
|
|
|
|
My English is not good.
But I mean something like that:
int count(POINTER head)<br />
{<br />
return head!=NULL ? count(head->next)+1 : 0 ;<br />
}
But not to return the value. I WANT TO DISPLAY THE VALUE.(and this is difficult)
|
|
|
|
|
Where do you want to display it? In a window? on a command line?
|
|
|
|
|
|
Console.WriteLine(myList.Count(myList.FirstNode))
seriously, you couldnt work this out? Swap to a different course while you still can.
|
|
|
|
|
It is a Data Structure work J4amieC. Anyway thank you.
|
|
|
|
|
Hi folks,
I have project writing rich text document on metafile using GDI
Now I'm trying to make it using GDI+
Problem: I can't draw it precisely!!
Test sample: create metafile 10x10 inces, draw strips 10, 9, 8 inches long:
<br />
RectangleF frame = new RectangleF(0f, 0f, 10f, 10f);<br />
Metafile mf;<br />
Graphics g1;<br />
<br />
using(Graphics gr = CreateGraphics())<br />
{<br />
IntPtr dc = gr.GetHdc();<br />
mf = new Metafile(@"c:\inch.emf", dc, frame, MetafileFrameUnit.Inch, EmfType.EmfOnly);<br />
gr.ReleaseHdc(dc);<br />
}<br />
g1 = Graphics.FromImage(mf);<br />
g1.PageUnit = GraphicsUnit.Inch;<br />
g1.DrawLine(Pens.Green, 0F, 1F, 10F, 1F);<br />
<br />
g1.DrawLine(Pens.Green, 0F, 3F, 9F, 3F);<br />
g1.DrawLine(Pens.Green, 0F, 5F, 8F, 5F);<br />
g1.DrawLine(Pens.GreenYellow, 1f, 0f, 1f, 10f);<br />
g1.DrawLine(Pens.GreenYellow, 3f, 0f, 3f, 9f);<br />
g1.DrawLine(Pens.GreenYellow, 5f, 0f, 5f, 8f); <br />
<br />
g1.Dispose();<br />
mf.Dispose();<br />
Strips are shorter than needed!!
Using other units (Milimeter, Pixel, Point, Document) produces different results - all invalid
Question: how to create precise EMF - with definite size
WBR Tim
|
|
|
|
|
Hi folks,
I have a data grid.And I want to drag a cell's context into datagrid's caption text by dragging it. How can I do this...
Please help
-- modified at 9:29 Wednesday 9th November, 2005
|
|
|
|
|
Hello, I am presented with the following problem and have tried desperately (over 12 hours) to solve it:
I have a string say "011010101" and I want to parse this string based on a table of values:
i = 0
m = 011
k = 10
e = 101
I want to construct an algorithm that will go through the string above and parse it assigning each value to their corresponding table value. Looking at it, I know that the string would become "011" , "0" , "10" , "101" which for this example would be "mike" in that order. Since "i" is the first thing I check, my code tries to form "0", "11010101", and nothing else will get extracted. I don't need code, but maybe some concepts I could build off of? Any help would be greatly appreciated.
I love to program!
|
|
|
|
|
A few thoughts:
if i=0 and m=011 how do you determine, when parsing, that a value of 0 is 'i' or the start of 'm'? The answer is that you need to have a defined way of making each value unique. A pointer for you would be to base your 0's and 1's from morse code, where this uniqueness is enforced - also morse (in case you dont know) is made up of dots and dashes - very fitting with your 1's and 0's
Ok, onto parsing the string - take a look at StringTokenizer's - there are at least two articles here on CP about the principle - and it is basically what you want - in (unwritten) code;
StringTokenizer st = new StringTokenizer("011010101");<br />
string convertedString = "";<br />
while(st.HasMoreTokens)<br />
{<br />
char nextChar = st.NextToken();<br />
convertedString += nextChar;<br />
}
|
|
|
|
|
This problem is potentially non-trivial.
There are two things your forgot to specify. The first is whether there can be more than one correct parsing for each string. For example, your string parsed to "mike", but (with the right additional codes) it could also have parsed to pratically any other alphanumeric output. This is key in determining when and how the algorithm should terminate. The second problem is one of scope. How long is the input string and how big is the table of values? The way the algorithm will work is to search through the space of ALL POSSIBLE parsings and output those that complete. Clearly, the bigger your input string and lookup table get, the more the chances of seeing a 'combinatorial explosion'.
If you answer these questions, I will help you write the algorithm. Please let me know if you are comfortable with embedded recursion, or your pefer iterative processes. The former is much more elegant, but with big inputs could create memory problems.
-- modified at 6:45 Wednesday 9th November, 2005
|
|
|
|
|
I prefer embedded recursion. There can be more than one correct parsing for each string, and for this example, the table is limited to the alphabet (lower-case and upper-case) and also '\n', ' ', and '\t'.
I love to program!
|
|
|
|
|
|
Hi Everyone,
If anyone could help me out i'd really appreciate it because this problem is really holding back the project. I'm getting the dreaded
Source File: c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config Line: 198 problem
which i'm pretty sure one or two of you might be familiar with seeing as there are threads on it all over the internet. The reason i'm posting this is because i've tried every solution on the threads i've seen and none work. Restarting the computer, adding a blank space to my web config file, turning off indexing service (it wasn't on in the first place), replacing the .DLL's with ones from their main build, clearing out the VS Cache and rebuilding. None of which worked, still the same error when i try to run my web project which leaves me at a virtual standstill as everything else i need to develop is dependent on this.
If anyone has a solution which is either a working variation of one of the above or a different way you found to get your web project back up and running i'd very much appreciate if you'd share it as i can't afford the time being wasted trying to find out whats wrong right now.
Cheers
|
|
|
|
|
Can anyone tell me please if its possible to bind a datagrid to an array of
objects (defined by me) so that when i update the contents of the array, the
data grid updates its display.
Any tips would be greatly appreciated.
Greg.
|
|
|
|
|
|
Hi
Please could someone help me to convert the following to Visual Basic.. or alternatively post a table driven version
It is a CRC16 algorithm using the polynomial (x16 + x15 + x2 + 1) used for very short strings.
I think (not sure) a test string of "123456789" should generate a hex checksum of: BD3B
Tks
Richard
static unsigned BitsSet (unsigned char ch)
{
unsigned n;
n = 0;
while (ch)
{
n += (ch & 1);
ch >>= 1;
}
return(n);
}
unsigned CRCof (const char *message, unsigned len)
{
unsigned i;
unsigned crc;
unsigned char k;
crc = 0;
for (i=0; i<len; i++)
{
k = (unsigned char)(message[i]) ^ crc;
crc = (crc / 256) ^ (k*128) ^(k*64);
if ((BitsSet(k) & 1) != 0)
crc ^= 0xC001;
}
return(crc);
}
|
|
|
|
|
Hi all,
I'm using ftp with the command "NLST *.*\r\n". After I send this command I get a reply:
"226 Transfer complete". I just want to get the file list, the weird thing is that
Sometimes the command works and sometimes doesnt.
The commands: USER, PASS, CWD and PASV work FINE before "NLST" command.
Any idea why?
thanx
-- modified at 6:29 Wednesday 9th November, 2005
|
|
|
|
|
I want to bind a ComboBox with a DataSet by supplying a datasource and
also want to specify ComboBox.valueMember and ComboBox.DisplayMember in a
windows form in C#. What i m trying is below the piece of code but i m
not getting the required result;
ComboBox1.DataSource = DataSet1;
ComboBox1.DisplayMember = "StudentName";
ComboBox1.ValueMember = "StudentID";
How to Bind ComboBox1 with DataSet1 ? Please correct the above code
snippt.
|
|
|
|
|
Try this snippet. I think you simply didn't bind to the Table, rather than the data set.
DataSet ds = new DataSet();
DataTable t = new DataTable("Students");
t.Columns.Add("StudentID", typeof(int));
t.Columns.Add("StudentName", typeof(string));
ds.Tables.Add(t);
for(int i = 0; i < 5; i++)
{
DataRow r = t.NewRow();
r["StudentID"] = i;
r["StudentName"] = "Test Student " + i.ToString();
t.Rows.Add(r);
}
comboBox1.DataSource = ds.Tables[0];
comboBox1.ValueMember = "StudentID";
comboBox1.DisplayMember = "StudentName"; Access the selected value:
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
|
|
|
|
|