Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C# - Cannot cast a number in a linked list to double
New Posts  All Forums:Forum Nav:

C# - Cannot cast a number in a linked list to double

post #1 of 6
Thread Starter 
Here is my code:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            OurList myList = new OurList();
            for (int i = 0; i < 10; i++)
                myList.PushBack(i);
            myList.LessThan(0);

            //Console.Write("Please enter the value you want to compare the myList to: ");
            //double number = Convert.ToInt32(Console.ReadLine());
            //Console.WriteLine("The 5th value on the list is {0}", myList.GetNthValue(5));

            Console.WriteLine();
            Console.WriteLine("Press any key to continue ...");
            Console.ReadKey();
        }
    }

    public class OurList
    {
        private class OurListNode
        {
            public double mData { get; set; }
            public OurListNode mNext { get; set; }
            public OurListNode(double d = 0, OurListNode ln = null)
            {
                mData = d;
                mNext = ln;
            }
        }

        private OurListNode mFirst;

        public OurList()     // shown in class notes
        {
            mFirst = null;
        }

        public void Clear()     // shown in class notes
        {
            mFirst = null;
        }

        public void PushFront(double number)     // shown in class notes
        {
            mFirst = new OurListNode(number, mFirst);
        }

        public void PopFront()     // shown in class notes
        {
            if (mFirst != null)
                mFirst = mFirst.mNext;
        }

        public void PushBack(double number)     // shown in class notes
        {
            if (mFirst == null)
                PushFront(number);
            else
            {
                OurListNode mTmp = mFirst;
                while (mTmp.mNext != null)
                    mTmp = mTmp.mNext;

                mTmp.mNext = new OurListNode(number, null);
            }
        }

        public void PopBack()     // shown in class notes
        {
            if (mFirst == null)
                return;
            else if (mFirst.mNext == null)
                PopFront();
            else
            {
                OurListNode pTmp = mFirst;
                while (pTmp.mNext != null && pTmp.mNext.mNext != null)
                    pTmp = pTmp.mNext;

                pTmp.mNext = null;
            }
        }

        public void Display()     // shown in class notes
        {
            OurListNode pTmp = mFirst;
            while (pTmp != null)
            {
                Console.Write("{0}, ", pTmp.mData);
                pTmp = pTmp.mNext;
            }
            Console.WriteLine();
        }

        public bool isEmpty()     // shown in class notes
        {
            if (mFirst == null)
                return true;
            else
                return false;
        }
        public OurList(OurList aList)   // a Deep copy
        {
            mFirst = null;
            OurListNode pCopy = aList.mFirst;

            while (pCopy != null)
            {
                PushBack(pCopy.mData);
                pCopy = pCopy.mNext;
            }
        }
        
        public void LessThan(double number)
        {
            OurListNode pTmp = mFirst;
            int counter = 0;
            if (pTmp.mNext != null)
            {
                pTmp = pTmp.mNext;
                if (pTmp < number)***************************************************************
                    counter++;
                Console.Write("{0}", counter);
            }
                


        }
    }
}


The starred area is where I am getting the following error:

Error1Operator '<' cannot be applied to operands of type 'ConsoleApplication1.OurList.OurListNode' and 'double'

I cannot figure out how to cast this variable as a double so I can find a method that will compare a value passed into the method to each number in the linked list to see if it is lessthan or greaterthan the passed number

Ideas?
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #2 of 6
Code:
if (pTmp.mData < number)

You're trying to compare the object itself with the number passed into the LessThan, rather than the data that it stores.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #3 of 6
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

Code:
if (pTmp.mData < number)

You're trying to compare the object itself with the number passed into the LessThan, rather than the data that it stores.

What would I call to access the data?
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #4 of 6
Quote:
Originally Posted by Zaxbys View Post


What would I call to access the data?

 

The first line of my post :)

Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #5 of 6
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

The first line of my post smile.gif

I was reading that from mobile and it didn't show that! thumb.gif

Thanks so much! +rep
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #6 of 6

You're welcome :)

Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C# - Cannot cast a number in a linked list to double