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. Searching for a matching item in a linked list based queue

Searching for a matching item in a linked list based queue

Scheduled Pinned Locked Moved C#
data-structurescsharpalgorithmsbeta-testingquestion
6 Posts 2 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.
  • A Offline
    A Offline
    Angelinna
    wrote on last edited by
    #1

    How do I search for a matching item in a linked list based queue.I have this set of items in a queue and would like to input a piece of data in a textbox and then find out if this piece of data exists in the queue and if it does/or doesn't gives me a feedback. (Am using C# ) Thanks.

    C 1 Reply Last reply
    0
    • A Angelinna

      How do I search for a matching item in a linked list based queue.I have this set of items in a queue and would like to input a piece of data in a textbox and then find out if this piece of data exists in the queue and if it does/or doesn't gives me a feedback. (Am using C# ) Thanks.

      C Offline
      C Offline
      c2423
      wrote on last edited by
      #2

      Sounds a little mixed up to me - do you want to use a list, or a queue, or a set? To check that an item exists you can use something like: List items = new List(); items.Add("ABC"); //etc bool itemExists = items.Exists(delegate(string match) { return String.Equals(match, TextBox1.Text); } ); You can also write a more complex delegate/predicate to do things like partial matches. Hope this helps, Chris

      A 1 Reply Last reply
      0
      • C c2423

        Sounds a little mixed up to me - do you want to use a list, or a queue, or a set? To check that an item exists you can use something like: List items = new List(); items.Add("ABC"); //etc bool itemExists = items.Exists(delegate(string match) { return String.Equals(match, TextBox1.Text); } ); You can also write a more complex delegate/predicate to do things like partial matches. Hope this helps, Chris

        A Offline
        A Offline
        Angelinna
        wrote on last edited by
        #3

        How can I use find() to accomplish that?

        C 1 Reply Last reply
        0
        • A Angelinna

          How can I use find() to accomplish that?

          C Offline
          C Offline
          c2423
          wrote on last edited by
          #4

          Its basically the same as Exists, but using strings rather then booleans:

          List<string> items = new List<string>();

                  items.Add("ABC");
                  //etc
          
                  string Result = items.Find(delegate(string match)
                                              {
                                                  return String.Equals(match, TextBox1.Text);
                                              });
          

          Hope this helps, Chris

          A 1 Reply Last reply
          0
          • C c2423

            Its basically the same as Exists, but using strings rather then booleans:

            List<string> items = new List<string>();

                    items.Add("ABC");
                    //etc
            
                    string Result = items.Find(delegate(string match)
                                                {
                                                    return String.Equals(match, TextBox1.Text);
                                                });
            

            Hope this helps, Chris

            A Offline
            A Offline
            Angelinna
            wrote on last edited by
            #5

            I need to input a number through a textbox and display a message in my outbox that tells me whether or not there is an item in the data queue whose number matches that input. My application is already able to initiate a data queue.

            C 1 Reply Last reply
            0
            • A Angelinna

              I need to input a number through a textbox and display a message in my outbox that tells me whether or not there is an item in the data queue whose number matches that input. My application is already able to initiate a data queue.

              C Offline
              C Offline
              c2423
              wrote on last edited by
              #6

              Ok - seems like you might be implimenting your own version of a Queue, which internally is using List? In which case you would need to work out an algorithm for this... Anyway, assuming you are using System.Collections.Generic.Queue<T> you can use the "Contains" method, for example:

              Queue<string> q = new Queue<string>();
              //Initialise Queue here

              bool b = q.Contains("Hello world");

              As for getting based on an ID number, Im not sure what you are wanting: -If you want to do this like an index number (i.e. "Get the second item in the queue"), you can use an iterator (see foreach), or can cast it to an array (using ToArray) before getting the value. -If each item in the Queue has a unique id number, which does not correspond to its index in the queue, you could try iterating until a condition is met For example:

              foreach(item x in queue)
              {
              if(x.Id == IdWeAreSearchingFor)
              {
              //Found a match, so do whatever we need to do with it
              break;
              }
              }

              Maybe one of these approaches will help you get a bit further, but if not let me know. It would be helpful to know if you are using Queue or making your own Queue class based on List if none of these suggestions helped! Chris

              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