Wrox Programmer Forums
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 8th, 2003, 02:40 AM
Authorized User
 
Join Date: Sep 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to conundrum Send a message via AIM to conundrum Send a message via Yahoo to conundrum
Default Link lists

I want to create a matrix using link lists in C#. I have been able to find how to create a link lists with links point in one direction but not in 4 directions. I want to be able to traverse the matrix up,down,left and right for ease of data manipulation. I know that this can be "Easily" done in older languages such as C++ and pascal but can not figure out how to do it in C#.



 
Old December 9th, 2003, 02:49 AM
Registered User
 
Join Date: Dec 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to guyhuang
Default

without using the UNSAFE code?
i found without pointer, things i can do became less and less.:)

i am a c# programmer learner in china.
hope to communicate with you.
 
Old December 9th, 2003, 04:25 PM
Authorized User
 
Join Date: Nov 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to KABay
Default

I don't know why but I feel the need to jump on this thread.

It may be that 'this can be "Easily" done in older languages such as C++ and pascal' but I don't believe it can be more easily done in C#. You still have to basiccaly 'roll your own' mechanisms for storing the 'links' and traversing them. But C# you may find doing something like creating a class to hold the matrix value and its four 'links' and then storing that 'object' in a hash table will make things 'easier'. Or you store your value and its four links in an XML document. In either case you have built-in (efficient) mechanisms for searching and retrieving data rather than having to build your own.

I personally would shudder at having to determine and keep track of four different relationships for each matrix cell. I hope all you have to do is traverse the matrix and change individual matrix values, not insert and/or remove cells to the matrix after it has been established.
 
Old December 9th, 2003, 04:30 PM
Authorized User
 
Join Date: Nov 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

C# is very like C and C++, but not identical. C# doesn't have pointers, instead it has references, like C++ does.

Using the ref keyword has the disadvantage of insisting that the value be initialized before being passed to the method. Fortunately, the out keyword saves us. Here’s a simple program using references.

using System;
public class SwapExample
{
    static void swap(ref int x, ref int y, out int sum)
    {
        int temp;
        temp = x;
        x = y;
        y = temp;
        sum = x + y;
    }
public static void Main()
    {
        int x = 1, y = 2, sum ;
        SwapExample.swap(ref x,ref y, out sum);
        Console.WriteLine("(after swap) x = {0} y = {1} sum = {2}",
            x,y,sum);
    }
}

You can do at least as much in C# and in C and C++, but slightly differently.

HtH



Sandra MacGregor
 
Old December 9th, 2003, 06:12 PM
Authorized User
 
Join Date: Nov 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

BTW,

I've not heard or seen a " 'matrix' = 2-dimensional" 'list'. A 'list' by definition is 1-dimensional. You can move up or down. There's no other dimension that would allow you to move accross.

If you want a 2-dimensional matrix, use a table = an array of arrays. C# is even better here than C or C++ because you can have a table = to an array of structs in which the dimension (size) of the elements in each struct = sub-array is different. That is, each row can be of a unique size. In this structure, to move in any of the 4 directions is done by indexing - really simple. You can also fill the table cells with references if you don't want the actual values there.


Sandra MacGregor





Similar Threads
Thread Thread Starter Forum Replies Last Post
foreach with two lists silasla C# 13 May 2nd, 2008 12:27 PM
Lists rickyoung Pro Visual Basic 2005 0 November 24th, 2006 09:04 AM
sorting lists treasacrowe Classic ASP Databases 2 August 20th, 2004 06:23 AM
Lists Martyn Forum and Wrox.com Feedback 9 June 6th, 2003 11:03 AM
Email Lists Jeff Mason Forum and Wrox.com Feedback 43 June 5th, 2003 11:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.