Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:22:48+00:00 2026-06-15T21:22:48+00:00

I am working with a link list. My constructor takes arrays with items in

  • 0

I am working with a link list. My constructor takes arrays with items in it or appends an item(one at time) to the list through BtnAddTree click. For experimental reasons I am trying to figure out a way to retrieve the position of an item from the list. I have set three buttons that will hopefully show: first, next, last item and display through a label. I created two functions to achieve my need Retrieve and Current_Tree() but here is where I come to a dead end. I am aware to display items that are next I may need to use a loop but unsure how to go about it. How can I display the position of an item found in the list?

        public class ListForTrees
        {

        //Retrieve Position of item
            public void Retrieve(int Position)
            {
                int new_position = Position;
                fruit_trees current = first_tree;

                for (int i = 0; i < Position && current != null; i++)
                {
                    current = current.next_tree;
                }
                return current;
            }

        //Show Current Tree
            public void Current_Tree()
            {
                try
                {
                    current = fruit_trees.first_tree;
                    labelSpecificTree.Text = current.Type.ToString();
                }
                catch { };

            }         



        }

        ListForTrees mainlist = new ListForTrees();     

        private void BtnGo_Click(object sender, EventArgs e)
        {
            fruit_trees[] ax = {   new fruit_trees("cherry", 48, 12.95, 3),
                                             new fruit_trees("pine", 36, 9.95, 8),
                                             new fruit_trees("oak", 60, 14.95, 2),
                                             new fruit_trees("peach", 54, 19.95, 3),
                                             new fruit_trees("pear", 36, 11.85, 2),
                                             new fruit_trees("apple", 62, 13.45, 5)
                                         };   
            mainlist = new ListForTrees(ax);
            fruit_trees current = mainlist.first_tree;   

            while (current != null)
            {
                TxtOutput.AppendText(current.ToString() + Environment.NewLine);
                current = current.next_tree;
            }
        }

        private void ShowNextItem_Click(object sender, EventArgs e)
        {
        //Show Next Item
        }

        private void ShowLastItem_Click(object sender, EventArgs e)
        {
        //Show Last Item
        }

        private void ShowFirstItem_Click_1(object sender, EventArgs e)
        {
        // Show First Item
        }


    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:22:49+00:00Added an answer on June 15, 2026 at 9:22 pm

    Develop a way to compare the object properly. is tree type unique? maybe you need a full icomparable?

    then create a method in the listoftrees class

    public int getPosition(fruit_trees tree)
    {
     fruit_trees ft = first_tree;
     if(ft.tree_type == tree.tree_type)
     {
          return 0; //or return 1 depending on how you want to index stuff
     }
     int i = 1;//possibly set to 2 if returning 1 above
     while(ft.next_tree != null)
     {
         ft = ft.next_tree;
         if(ft.tree_type == tree.tree_type)
         {
            return i; 
         }
         i++;
     }
    
     return -1; //or something else here to show that its not in the list
    
    }
    

    also as a side note ..Dont set the label value in the class in the method Current_Tree(). That should return a fruit_trees object and the btn click methods should set the label value .

    you should actually just get rid of that method completely(unless there is some reason for it outside of the code above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a link list. I have set my constructor to take
I am working with a link list. The list has items based on inserted
I am currently working with a link list of items. I am aware of
I'm working through an iPhone tutorial ( link text and it has me put
I am working with a link list. The list is brought up on the
I'm working towards generating a list into my view. When attempting to loop through
I am working on a small script where there are some list items. If
I am working on python plugins.I used QTreeWidget to list items. [listing in qtreewidget][1]
I'm working on a website where one of the pages has a list of
As we are working locally so our service link is: http://localhost:8012/webservice.asmx When we deploy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.