Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mia023
    New Member
    • May 2007
    • 89

    Help

    Hello everbody,
    I just need yo ask a few questions:
    1.How to delete elements in an array
    2.How to reverse an array

    and Does any one know a good tutorial for Linked List(singly and Doubly and circular )
    Thank you
  • mia023
    New Member
    • May 2007
    • 89

    #2
    Originally posted by mia023
    Hello everbody,
    I just need yo ask a few questions:
    1.How to delete elements in an array
    2.How to reverse an array

    and Does any one know a good tutorial for Linked List(singly and Doubly and circular )
    Thank you
    Sorry again but another question is:
    Is the Node of a linked List considered an object?

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by mia023
      Sorry again but another question is:
      Is the Node of a linked List considered an object?
      Yup, in Java deep down your elements in the list are stored in some object and
      Java consider it none of your business what that object is, i.e. all you need to
      know is that one of your elements can be retrieved from it and you don't even
      have to do that yourself.

      w.r.t. your first questions:

      - you cannot delete an element from your array such that your array ends up
      one element shorter. All you can do is store a 'sentinel' value somewhere in
      your array indicating that no element should be considered present there.

      - reversing an array is done by swapping the first and the last element etc. etc.
      until all elements are swapped.

      kind regards,

      Jos

      Comment

      • mia023
        New Member
        • May 2007
        • 89

        #4
        public static void remove(int a[],int element){
        int size=a.length;
        for(int i=0;i<a.length; i++){
        if(a[i]==element)
        a[i]=0;

        }
        size--;

        Is this correct

        Comment

        • Laharl
          Recognized Expert Contributor
          • Sep 2007
          • 849

          #5
          Assuming that your other code knows to ignore a 0 anywhere in the array, yes, it's fine.

          Comment

          • mia023
            New Member
            • May 2007
            • 89

            #6
            Originally posted by Laharl
            Assuming that your other code knows to ignore a 0 anywhere in the array, yes, it's fine.
            I really need urgent help in Linked List(single,dou ble,circular)
            I can't understand their implementation.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by mia023
              [code=java]public static void remove(int a[],int element){
              int size=a.length;
              for(int i=0;i<a.length; i++){
              if(a[i]==element)
              a[i]=0;

              }
              size--;[/code]
              Is this correct
              Note that the size of the array won't get shorter because of doing size--;
              Read again what I wrote above.

              kind regards,

              Jos

              ps. use 'code' tags, not 'b' tags.

              Comment

              Working...