Results 1 to 13 of 13
Like Tree1Likes
  • 1 Post By foulkelore

Thread: need help Write code link list

  1. #1
    falcon2000 is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default need help Write code link list

    hello to all i am new at JAVA and i need yours help on some Exercise

    this is the code i get and i need to build some constractor and Methods.

    i cant use java build in only String class is aprove


    PHP Code:
    public class CharNode
      {
          private char _data;
          private int _value;
          private CharNode _next;
          public CharNode(char c, int val, CharNode n) 
            {
                 _data = c;
                 _value = val;
                 _next = n;
            }
          public CharNode getNext( ) { return _next; }
          public void setNext(CharNode node) { _next = node; }
          public int getValue() { return _value; }
          public void setValue(int v) { _value = v; }
          public char getData() { return _data; }
          public void setData(char c) { _data = c; }
     }
    this the String List class

    PHP Code:
    public class StringList
        {
             private CharNode _head;
    
             public StringList( ) {
                    _head = null;
                 }
             public StringList(CharNode node) {
                      if (node==null)
                              _head = null;
                      else
                         {
                              _head = new CharNode (node.getData(),node.getValue(), null);
                              for(CharNode ptr= node.getNext(),last=_head; ptr!= null; ptr= ptr.getNext())
                                       {
                                            last.setNext(new CharNode(ptr.getData(),ptr.getValue(), ptr.getNext()));
                                            last = last.getNext();
                        }
                 }
         }
    }
    [/PHP]now i need this constartor and Methods.

    public StringList (String s) : that must add StringList class constructor receiving a string of characters and builds from a list that represents
    The string specified above.

    public StringList (StringList other) : Copy constructor receiving another StringList string and copies the values.

    public char charAt(int i) :Returns the character instead of the string i
    Represented - by object class StringList. Assumed that the value of i is within
    Correct.

    public StringList concat (StringList str) :That returns a string
    Consisting of the string it is turned on and the end is threaded string str. The method does not
    Change the string on which it is running.

    public int indexOf (int ch) : Returns the index in the string represented
    The - by the object it is turned on the first occurrence of the character ch. If the character does not appear in ch
    String, -1 is returned. Please note, the parameter conveys the character ch methods indexOf is
    Type int and char. String class so that, if we draw a character and not a whole number, actually
    Transferred its code value, which is fine.

    public int indexOf (int ch, int fromIndex): Returns the index
    String represented - by the object it is turned on the first occurrence of the character, ch
    When the search begins in the index fromIndex. If the character ch appears in the string not be returned -
    One. If the value of fromIndex out of range, the method returns

    public boolean equals (StringList str) Returns true if
    String represented - by the object it is on the same string is represented - by
    Str object. Otherwise false is returned. This system must write recursion, without
    Using loops in general.

    public int compareTo (StringList str) :Comparing a string
    Represented - by the object it is enabled represented string method - by object
    str parameter. The method returns the value 0 if the strings are equal. If the string
    Small an object lexicographic string str parameter returned a negative number, and if
    Large object string string str lexicographic positive value is returned.

    public StringList substring(int i):urns the second part begins
    Where the i string represented - by the object on which it is enabled. That is, the sub -
    String from the i to the end of the string. For example, if the "s =" abc then
    s.substring (1) returns the "bc". Assumed that the value of i is the right term. The method does not
    Change the string on which it is running.

    public StringList substring(int i, int j):Returns the sub -
    String that begins where the i and ends where the j (not including) the string represented -
    By the object on which it is enabled. For example, if the "s =" abcdefg then
    s.substring (2,5) returns the "cde". Assumed that the values ​​of i and j are within
    Correct. The method does not change the string on which it is running.

    public String toString()


    i cant use java build in only String class is aprove


    pls i need your help

    best regards
    Last edited by falcon2000; 01-17-2013 at 09:09 PM.

  2. #2
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: need help Write code link list

    Start small. Get the first thing to work and then move on, but we are not going to do your homework for you. Give it a try and post any errors and or code you have and we will help.
    DarrylBurke likes this.

  3. #3
    falcon2000 is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: need help Write code link list

    Quote Originally Posted by foulkelore View Post
    Start small. Get the first thing to work and then move on, but we are not going to do your homework for you. Give it a try and post any errors and or code you have and we will help.

    that what i do, i dont ask you to do my homework,that what i do and i need help on the other

    PHP Code:
    private CharNode _head;
    private String _myStirng="";
    
    public StringList (String S)
       {
           CharNode temp = _head;
           int count = 0;
           if (temp!=null&&s.length()!=-1)
               for (int i=0;i<s.length();i++)
                  {
                      count =counterChar (s.chatAt(i),s);
                      char x = s.charAt(i);
                      temp = new CharNode (x,count,temp);
                   }
       }
    
    public StringList (StringList other)
          {
              if (other._head ==null)
                   _head =null;
              else
                  {
                     CharNode ptr = other._head;
                     _head=new CharNode(_head.getData(),_head.getValue(),_head.getNext);
                     CharNode newNode = _head;
                     while (ptr!=null)
                            {
                                  newNode.setNext(new CharNode(ptr.getData(),ptr.getValue(),ptr.getNext());
                                  ptr = ptr.getNext;
                             }
                   }
         }
    
    public char charAt(int i)
         {
              ChatNode p =_head;
              char count;
              int index =0;
             while(p!=null&&p.getData()!=i)
                   {
                       p=p.getNext();
                       count =charAt(index);
                       index++;
                   }
             return p.getData();
        }
    
    public StringList concat (StringList str)
             {
                   CharNode p;
                   String concat ="";
                   if (_head==null)
                        return new StringList (str._head);
                   else
                        {
                           for (p=_head;p!=null;p=p.getNext())
                                 concat+ =p.getData();
                           for(p=str._head;p!=null;p.getNext())
                                 concat+=p.getData();
                           return new StringList (concat);
                        }
              }
    
    public int length()
           {
                CharNode p;
                 int count =0;
                 for(p=_head;p!=null;p.getNext())
                       count++
                 return count;
           } 
    public int indexOf (int ch)
            {
                  int count;
                  String temp = getString();
                  count = counter(temp,ch);
                  return count;
             }
    
    public String toStirng ()
           {
                CharNode p;
                String display = "";
                for (p=_head;p.getNext()!=null;p.getNext())
                       {
                            display+=p.getData()+""+p.getValue()+""+p.getNext();
                       }
                return display;
           }
    
    //my use only
    
    private int counterChar (char a,String s)
         {
            int count =0;
            for (int i =0;i<s.length();i++)
                 { 
                    if (s.charAt(i)==a)
                        count++;
                  }
            return count;
         }
    
    
    
    
    private int counter (String S,int ch)
          {
                int count=0;
                for (int i=0;s.length();i++)
                      {
                            if (s.charAt(i)==ch)
                                   count++;
                            else
                                   count -1;
                      }
                return count;
           }
    
    private void setString (String S)
            {
                _myString =s;
             }
    
    private String getString()
         {
              return _myString;
         }
    Last edited by falcon2000; 01-17-2013 at 11:46 PM.

  4. #4
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: need help Write code link list

    So - where is your exact problem now in the code above?
    I like likes!

  5. #5
    falcon2000 is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: need help Write code link list

    i dont know how to do this

    public boolean equals (StringList str) Returns true if
    String represented - by the object it is on the same string is represented - by
    Str object. Otherwise false is returned. This system must write recursion, without
    Using loops in general.

    public int compareTo (StringList str) :Comparing a string
    Represented - by the object it is enabled represented string method - by object
    str parameter. The method returns the value 0 if the strings are equal. If the string
    Small an object lexicographic string str parameter returned a negative number, and if
    Large object string string str lexicographic positive value is returned.

    public StringList substring(int i):urns the second part begins
    Where the i string represented - by the object on which it is enabled. That is, the sub -
    String from the i to the end of the string. For example, if the "s =" abc then
    s.substring (1) returns the "bc". Assumed that the value of i is the right term. The method does not
    Change the string on which it is running.

    public StringList substring(int i, int j):Returns the sub -
    String that begins where the i and ends where the j (not including) the string represented -
    By the object on which it is enabled. For example, if the "s =" abcdefg then
    s.substring (2,5) returns the "cde". Assumed that the values ​​of i and j are within
    Correct. The method does not change the string on which it is running.

  6. #6
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: need help Write code link list

    For your first problem you want a public function that returns a boolean(True or False). This might help get you started. Try something compile and test. Let us know if you have an questions about your code not the assignment.



    Java Code:
    public boolean isTrue(String value) {
         if (value.equals("true"))
              return true;
         else
              return false;
    }

  7. #7
    falcon2000 is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: need help Write code link list

    on this public boolean equals (StringList str) ,need to be recursion, without
    Using loops in general.

    i know how to do it ,but i dont know how to use recursion to do it

  8. #8
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: need help Write code link list

    Do you know what recursion is? I did a simple google search and found loads of examples. Give it a try yourself and post any code thats causing you problems.

  9. #9
    falcon2000 is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: need help Write code link list


  10. #10
    falcon2000 is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: need help Write code link list

    that what i do

    can someone check if it ok ?


    PHP Code:
    public boolean equals(StringList str) {
    
    
            CharNode ptr = _head;
    
    
            CharNode ptr2 = str.getHead();
            if (ptr == null || ptr2 == null) 
                        return false;
    
            else if (ptr.getData() == ptr2.getData() && ptr.getValue() == ptr2.getValue())
    
                               return true;
                  else return new StringList(ptr.getNext()).equals(new StringList(ptr2.getNext()));

  11. #11
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: need help Write code link list

    Did you try and compile it and run it? I don't think it will compile. Also are you calling the function from within the function? I think something like this is what your looking for. This is not my example I did get it from here.

    Java Code:
    void myMethod( int counter) {
         if(counter == 0)
              return;
         else {
              System.out.println(""+counter);
              myMethod(--counter);
              return;
         }
    }

  12. #12
    falcon2000 is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: need help Write code link list

    the code is compile ,that call recursion that the Methods call itsalfe.

    this not good way,but i ask to do this Methods at recursion .

    Methods i get other StringList and see if is equal to the string that call the Methods.


    Now i need this methods to build to end my program

    public int compareTo (StringList str) :Comparing a string
    Represented - by the object it is enabled represented string method - by object
    str parameter. The method returns the value 0 if the strings are equal. If the string
    Small an object lexicographic string str parameter returned a negative number, and if
    Large object string string str lexicographic positive value is returned.

    public StringList substring(int i):urns the second part begins
    Where the i string represented - by the object on which it is enabled. That is, the sub -
    String from the i to the end of the string. For example, if the "s =" abc then
    s.substring (1) returns the "bc". Assumed that the value of i is the right term. The method does not
    Change the string on which it is running.

    public StringList substring(int i, int j):Returns the sub -
    String that begins where the i and ends where the j (not including) the string represented -
    By the object on which it is enabled. For example, if the "s =" abcdefg then
    s.substring (2,5) returns the "cde". Assumed that the values ​​of i and j are within
    Correct. The method does not change the string on which it is running.


    can someone help me

  13. #13
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: need help Write code link list

    Now that you got one done step through the other the same way, use google for examples, post any code your working on that you are having problems with.

Similar Threads

  1. Auto-completion of code when when I write code
    By nutzu2011 in forum Eclipse
    Replies: 0
    Last Post: 04-06-2012, 08:01 PM
  2. Link list help
    By Poles_Apart in forum New To Java
    Replies: 5
    Last Post: 02-28-2012, 02:18 PM
  3. How to link a Array elemant to a Linked list Node
    By ravinda in forum New To Java
    Replies: 2
    Last Post: 04-18-2009, 10:16 AM
  4. Write a List into a Text file
    By tech2000 in forum New To Java
    Replies: 1
    Last Post: 11-13-2008, 06:09 AM
  5. Link List
    By one198 in forum New To Java
    Replies: 0
    Last Post: 10-14-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •