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