Results 1 to 13 of 13
Thread: need help Write code link list
- 01-17-2013, 08:00 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 7
- Rep Power
- 0
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
this the String List classPHP 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; } }
[/PHP]now i need this constartor and Methods.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(); } } } }
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 regardsLast edited by falcon2000; 01-17-2013 at 08:09 PM.
- 01-17-2013, 09:08 PM #2
Member
- Join Date
- Dec 2012
- Location
- Des Moines, IA
- Posts
- 33
- Rep Power
- 0
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.
- 01-17-2013, 10:41 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 7
- Rep Power
- 0
Re: need help Write code link list
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 10:46 PM.
- 01-17-2013, 11:07 PM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: need help Write code link list
So - where is your exact problem now in the code above?
I like likes!.gif)
- 01-18-2013, 12:55 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 7
- Rep Power
- 0
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.
- 01-18-2013, 02:26 PM #6
Member
- Join Date
- Dec 2012
- Location
- Des Moines, IA
- Posts
- 33
- Rep Power
- 0
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; }
- 01-18-2013, 02:35 PM #7
Member
- Join Date
- Jan 2013
- Posts
- 7
- Rep Power
- 0
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
- 01-18-2013, 03:26 PM #8
Member
- Join Date
- Dec 2012
- Location
- Des Moines, IA
- Posts
- 33
- Rep Power
- 0
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.
- 01-18-2013, 03:57 PM #9
Member
- Join Date
- Jan 2013
- Posts
- 7
- Rep Power
- 0
Re: need help Write code link list
- 01-18-2013, 05:55 PM #10
Member
- Join Date
- Jan 2013
- Posts
- 7
- Rep Power
- 0
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()));
- 01-18-2013, 07:44 PM #11
Member
- Join Date
- Dec 2012
- Location
- Des Moines, IA
- Posts
- 33
- Rep Power
- 0
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; } }
- 01-18-2013, 07:52 PM #12
Member
- Join Date
- Jan 2013
- Posts
- 7
- Rep Power
- 0
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
- 01-18-2013, 09:30 PM #13
Member
- Join Date
- Dec 2012
- Location
- Des Moines, IA
- Posts
- 33
- Rep Power
- 0
Similar Threads
-
Auto-completion of code when when I write code
By nutzu2011 in forum EclipseReplies: 0Last Post: 04-06-2012, 07:01 PM -
Link list help
By Poles_Apart in forum New To JavaReplies: 5Last Post: 02-28-2012, 01:18 PM -
How to link a Array elemant to a Linked list Node
By ravinda in forum New To JavaReplies: 2Last Post: 04-18-2009, 09:16 AM -
Write a List into a Text file
By tech2000 in forum New To JavaReplies: 1Last Post: 11-13-2008, 05:09 AM -
Link List
By one198 in forum New To JavaReplies: 0Last Post: 10-14-2007, 01:33 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks