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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Finding an item in linked list (CList)

Finding an item in linked list (CList)

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 Posts 4 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.
  • V Offline
    V Offline
    VCProgrammer
    wrote on last edited by
    #1

    Hi all, I have made a linked list using CList class. Inside parameters of CList i have passed structure which has value of CString and int aray type. If i want to find a item in that list using find function, how can i do it?

    struct Person
    {
    int ID;
    CString Name;
    int age;
    int phno[20];

    };

    CList person_struct;

    void function_add()
    {
    Person *obj_Per;

    obj\_Per->ID = 0;
    obj\_Per->Name = "Bilbo Baggins";
    obj\_Per->age = "35";
    for(int i = 0; i<20; i++)
    {
    	obj\_Per->phno\[i\] = i;
    }
    person\_struct.AddTail(obj\_Per);
    
    obj\_Per->ID = 1;
    obj\_Per->Name = "Fredo Frog";
    obj\_Per->age = "40";
    for(int i = 0; i<20; i++)
    {
    	obj\_Per->phno\[i\] = i;
    }
    person\_struct.AddTail(obj\_Per);
    

    }

    If i want to find item with particular ID then how can i do this?? Thanks in advance

    L D S 3 Replies Last reply
    0
    • V VCProgrammer

      Hi all, I have made a linked list using CList class. Inside parameters of CList i have passed structure which has value of CString and int aray type. If i want to find a item in that list using find function, how can i do it?

      struct Person
      {
      int ID;
      CString Name;
      int age;
      int phno[20];

      };

      CList person_struct;

      void function_add()
      {
      Person *obj_Per;

      obj\_Per->ID = 0;
      obj\_Per->Name = "Bilbo Baggins";
      obj\_Per->age = "35";
      for(int i = 0; i<20; i++)
      {
      	obj\_Per->phno\[i\] = i;
      }
      person\_struct.AddTail(obj\_Per);
      
      obj\_Per->ID = 1;
      obj\_Per->Name = "Fredo Frog";
      obj\_Per->age = "40";
      for(int i = 0; i<20; i++)
      {
      	obj\_Per->phno\[i\] = i;
      }
      person\_struct.AddTail(obj\_Per);
      

      }

      If i want to find item with particular ID then how can i do this?? Thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See the Remarks section here[^].

      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

      1 Reply Last reply
      0
      • V VCProgrammer

        Hi all, I have made a linked list using CList class. Inside parameters of CList i have passed structure which has value of CString and int aray type. If i want to find a item in that list using find function, how can i do it?

        struct Person
        {
        int ID;
        CString Name;
        int age;
        int phno[20];

        };

        CList person_struct;

        void function_add()
        {
        Person *obj_Per;

        obj\_Per->ID = 0;
        obj\_Per->Name = "Bilbo Baggins";
        obj\_Per->age = "35";
        for(int i = 0; i<20; i++)
        {
        	obj\_Per->phno\[i\] = i;
        }
        person\_struct.AddTail(obj\_Per);
        
        obj\_Per->ID = 1;
        obj\_Per->Name = "Fredo Frog";
        obj\_Per->age = "40";
        for(int i = 0; i<20; i++)
        {
        	obj\_Per->phno\[i\] = i;
        }
        person\_struct.AddTail(obj\_Per);
        

        }

        If i want to find item with particular ID then how can i do this?? Thanks in advance

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        VCProgrammer wrote:

        obj_Per->age = "35";

        Isn't the age member an int?

        VCProgrammer wrote:

        If i want to find item with particular ID then how can i do this??

        At this point, I'd be more concerned with adding an item properly. obj_Per has not been initialized (for each item).

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

        L 1 Reply Last reply
        0
        • D David Crow

          VCProgrammer wrote:

          obj_Per->age = "35";

          Isn't the age member an int?

          VCProgrammer wrote:

          If i want to find item with particular ID then how can i do this??

          At this point, I'd be more concerned with adding an item properly. obj_Per has not been initialized (for each item).

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Well spotted, I failed to notice that.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          1 Reply Last reply
          0
          • V VCProgrammer

            Hi all, I have made a linked list using CList class. Inside parameters of CList i have passed structure which has value of CString and int aray type. If i want to find a item in that list using find function, how can i do it?

            struct Person
            {
            int ID;
            CString Name;
            int age;
            int phno[20];

            };

            CList person_struct;

            void function_add()
            {
            Person *obj_Per;

            obj\_Per->ID = 0;
            obj\_Per->Name = "Bilbo Baggins";
            obj\_Per->age = "35";
            for(int i = 0; i<20; i++)
            {
            	obj\_Per->phno\[i\] = i;
            }
            person\_struct.AddTail(obj\_Per);
            
            obj\_Per->ID = 1;
            obj\_Per->Name = "Fredo Frog";
            obj\_Per->age = "40";
            for(int i = 0; i<20; i++)
            {
            	obj\_Per->phno\[i\] = i;
            }
            person\_struct.AddTail(obj\_Per);
            

            }

            If i want to find item with particular ID then how can i do this?? Thanks in advance

            S Offline
            S Offline
            smileangle
            wrote on last edited by
            #5

            you can use GetAt function Gets the element at a given position. please look for the MSDN CList member function :)

            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