Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. linked list in 2.0 and the error:

linked list in 2.0 and the error:

Scheduled Pinned Locked Moved C#
helpdata-structuresquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nesfrank
    wrote on last edited by
    #1

    Guys, I am trying to do the following but I get some conversion errors. can someone help me please? Class: public class Widget { public string RSP = ""; public int WidgetOrDiscount = 0; public decimal Price = 0.0m; } Console apps: static void Main(string[] args) { //LinkedList<System.String> myList = new LinkedList<System.String>(); LinkedList<Assignment3.Widget> myList = new LinkedList<Assignment3.Widget>(); PopulateData(ref myList); } private static void PopulateData(ref LinkedList<Widget> myList) { //record 001 Widget wdg1 = new Assignment3.Widget(); wdg1.RSP = "R"; wdg1.WidgetOrDiscount=150; wdg1.Price=1.00m; myList.AddFirst(wdg1); //record 002 Widget wdg2 = new Assignment3.Widget(); wdg2.RSP = "R"; wdg2.WidgetOrDiscount = 130; wdg2.Price = 2.00m; myList.AddAfter(wdg1, wdg2); //record 003 Widget wdg3 = new Assignment3.Widget(); wdg3.RSP = "S"; wdg3.WidgetOrDiscount = 145; wdg3.Price =0.00m; myList.AddAfter(wdg2, wdg3); //record 004 Widget wdg4 = new Assignment3.Widget(); wdg4.RSP = "R"; wdg4.WidgetOrDiscount = 50; wdg4.Price = 2.50m; myList.AddAfter(wdg3, wdg4); } Please help me.

    E 1 Reply Last reply
    0
    • N nesfrank

      Guys, I am trying to do the following but I get some conversion errors. can someone help me please? Class: public class Widget { public string RSP = ""; public int WidgetOrDiscount = 0; public decimal Price = 0.0m; } Console apps: static void Main(string[] args) { //LinkedList<System.String> myList = new LinkedList<System.String>(); LinkedList<Assignment3.Widget> myList = new LinkedList<Assignment3.Widget>(); PopulateData(ref myList); } private static void PopulateData(ref LinkedList<Widget> myList) { //record 001 Widget wdg1 = new Assignment3.Widget(); wdg1.RSP = "R"; wdg1.WidgetOrDiscount=150; wdg1.Price=1.00m; myList.AddFirst(wdg1); //record 002 Widget wdg2 = new Assignment3.Widget(); wdg2.RSP = "R"; wdg2.WidgetOrDiscount = 130; wdg2.Price = 2.00m; myList.AddAfter(wdg1, wdg2); //record 003 Widget wdg3 = new Assignment3.Widget(); wdg3.RSP = "S"; wdg3.WidgetOrDiscount = 145; wdg3.Price =0.00m; myList.AddAfter(wdg2, wdg3); //record 004 Widget wdg4 = new Assignment3.Widget(); wdg4.RSP = "R"; wdg4.WidgetOrDiscount = 50; wdg4.Price = 2.50m; myList.AddAfter(wdg3, wdg4); } Please help me.

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      AddBefore and AddAfter require list nodes as arguments. Whereas AddFirst and AddLast do not.

      Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
      Most of this sig is for Google, not ego.

      N 2 Replies Last reply
      0
      • E Ennis Ray Lynch Jr

        AddBefore and AddAfter require list nodes as arguments. Whereas AddFirst and AddLast do not.

        Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
        Most of this sig is for Google, not ego.

        N Offline
        N Offline
        nesfrank
        wrote on last edited by
        #3

        can u give me an example with node? does it accepts object type or only string? please help.

        1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          AddBefore and AddAfter require list nodes as arguments. Whereas AddFirst and AddLast do not.

          Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
          Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
          Most of this sig is for Google, not ego.

          N Offline
          N Offline
          nesfrank
          wrote on last edited by
          #4

          I used addbefore and addafter. how can I loop to display the items in a console app for the linked lists? I see online saying >ForEachLoop but it does not work,

          P 1 Reply Last reply
          0
          • N nesfrank

            I used addbefore and addafter. how can I loop to display the items in a console app for the linked lists? I see online saying >ForEachLoop but it does not work,

            P Offline
            P Offline
            Pedram Behroozi
            wrote on last edited by
            #5

            1st, I think it's better that you write your LinkedList like this:

            LinkedList<string> ll = new LinkedList<string>();
            LinkedListNode<string> lln = new LinkedListNode<string>(Console.ReadLine());

            ll.AddFirst(lln);
            LinkedListNode<string> Prelln = null;

            while (true)
            {
            Prelln = lln; // Save the current Node,

            string input = Console.ReadLine();
            if (input == "End") // If user type "End", Done!
                break;
            
            lln = new LinkedListNode<string>(input); // Otherwise, Add a new Node
            ll.AddAfter(Prelln, lln); // Add new Node after previous saved Node
            

            }

            It takes less memory. [Edit] However, It's your choice ;) [\Edit] 2nd, a simple foreach gets you your nodes, for this example:

            foreach (string i in ll)
            Console.WriteLine(i);

            While (true) { Human.isLearnable = true; }

            modified on Tuesday, October 21, 2008 2:41 PM

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups