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. How do I write this java code in C#

How do I write this java code in C#

Scheduled Pinned Locked Moved C#
csharpjavadatabasedata-structuresquestion
9 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.
  • A Offline
    A Offline
    Angelinna
    wrote on last edited by
    #1

    // Search Operations // I am trying to search a textbox entry in a linkedlist queue implementation such that if the entry is there in the recorded queue then I get a message that it is actually there. Thanks --------------------------------------------------------------------- public int indexOf(Object o) { int index = 0; if (o==null) { for (Entry e = header.next; e != header; e = e.next) { if (e.element==null) return index; index++; } } else { for (Entry e = header.next; e != header; e = e.next) { if (o.equals(e.element)) return index; index++; } } return -1; }

    M 1 Reply Last reply
    0
    • A Angelinna

      // Search Operations // I am trying to search a textbox entry in a linkedlist queue implementation such that if the entry is there in the recorded queue then I get a message that it is actually there. Thanks --------------------------------------------------------------------- public int indexOf(Object o) { int index = 0; if (o==null) { for (Entry e = header.next; e != header; e = e.next) { if (e.element==null) return index; index++; } } else { for (Entry e = header.next; e != header; e = e.next) { if (o.equals(e.element)) return index; index++; } } return -1; }

      M Offline
      M Offline
      Mogaambo
      wrote on last edited by
      #2

      Why don't you implement the in built Binary search method, if you use ArrayList class.

      “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

      modified on Wednesday, September 10, 2008 4:48 AM

      A L 2 Replies Last reply
      0
      • M Mogaambo

        Why don't you implement the in built Binary search method, if you use ArrayList class.

        “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

        modified on Wednesday, September 10, 2008 4:48 AM

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

        How do I do that...

        M 1 Reply Last reply
        0
        • A Angelinna

          How do I do that...

          M Offline
          M Offline
          Mogaambo
          wrote on last edited by
          #4

          //Create a object System.Collections.ArrayList oArrayList = new System.Collections.ArrayList(); // Add all your entries in ArrayList Object in form load event or the event which suited your problem oArrayList.add(/* Your entry*/); //then search for a value whether it exists or not bool isexist=oArrayList.contains("Your search value");//method returns true if your search value exist.

          “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

          N 1 Reply Last reply
          0
          • M Mogaambo

            //Create a object System.Collections.ArrayList oArrayList = new System.Collections.ArrayList(); // Add all your entries in ArrayList Object in form load event or the event which suited your problem oArrayList.add(/* Your entry*/); //then search for a value whether it exists or not bool isexist=oArrayList.contains("Your search value");//method returns true if your search value exist.

            “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            Mogaambo wrote:

            System.Collections.ArrayList

            Use a strongly typed generic List<T> instead of arraylist.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

            A 1 Reply Last reply
            0
            • N N a v a n e e t h

              Mogaambo wrote:

              System.Collections.ArrayList

              Use a strongly typed generic List<T> instead of arraylist.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

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

              Have got the linkedlist running with data stored in a queue already but not sure of how to search through the queue whether the textbox entry exists in the queue or not.

              N 1 Reply Last reply
              0
              • A Angelinna

                Have got the linkedlist running with data stored in a queue already but not sure of how to search through the queue whether the textbox entry exists in the queue or not.

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #7

                Angelinna wrote:

                data stored in a queue

                Your question is not clear. Are you using a generic Queue<T>? if yes, it has a Contains()[^] method which can be used.

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                A 1 Reply Last reply
                0
                • M Mogaambo

                  Why don't you implement the in built Binary search method, if you use ArrayList class.

                  “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

                  modified on Wednesday, September 10, 2008 4:48 AM

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #8

                  Mogaambo wrote:

                  Binary search

                  On a linked list? :sigh:

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 4a out now (29 May 2008)

                  1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    Angelinna wrote:

                    data stored in a queue

                    Your question is not clear. Are you using a generic Queue<T>? if yes, it has a Contains()[^] method which can be used.

                    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

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

                    How do I use the contains()

                    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