marc perry batuigas

Greenhorn
+ Follow
since May 05, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by marc perry batuigas

ty man, but i kinda solved it already... i was missing a method which converts the "list" into strings...anyway i'm working on trees right now...will let u guys know if i have some trouble with it...thanks!
20 years ago
intermediate?? but i'm just a beginner!!! *bump

anyway, i'm trying to make a program which does on "relating" with other predefined classes...like the last program i presented here last--MyLinkedList(i just copied the methods and constructors somewhere in the net, but i'm proud to say that i made the main, which by the way is the most important part in my project, with help of course from you guyz)...

i just need to know how to incorporate certain classes without using "extends" and "implements" calls...

i'm workin on linked deque..fyi...
20 years ago
can someone please show me a good (clear) pseudocode or an algorithm perhaps (a code, the better )in implementing deque as singly linked list....

i've been trying to make-up a code, but i can't quite make it work...i need the code to be placed in a single page, i mean, without "referencing" to other classes or other java file...i would really really appreciate it if someone could help me...

No need to shout. I removed the !!...!! from your subject. - Gregg
[ May 14, 2004: Message edited by: Gregg Bolinger ]
20 years ago
got the solution already guyz...LOLz
this forum really helped me alot...hope u continue to help others too sa u did for me...thanks a million and more POWER!
20 years ago

20 years ago
it's me again... er, still got a question to ask bout my last program, this time it concerns calling methods...well in my program (MyLinkedList), i used bufferedreader to read the text file, then put it again on StrongTokenizer to read each character of the text file, in a line...assuming i have already initialized the linkedlist into my main and bufferedReader has read the file, and stringTokenizer is reading a line, i want to call, say, remove, how do i call the methods while still in the stringTokenizer?
really need some answers guys, this is my 2nd year as BSIT, and i'm doing my best to love java...and MyLinkedList is just one of the three of my school projects. hope to hear from someone soon...
20 years ago
ic! i tried that last time, but did this :
code:
String line = null;
while(line!=null)
{
line = inputStream.readLine();
}
----
did'nt like the way it reads...
haven't thought of that...thanks man
oh and one more thing...i just realized how hard it is to call back the functions/methods of Linklist when the line is already contained into the tokenizer, the "ifs" part...so how do i call the methods, e.g. remove,add, etc...
20 years ago
hi, i'm a student(BSIT) and i'm having a hard time figuring out how to make my code work...
about my code: it is called MyLinkedList.java. Unfinished because i got stuck with the loops! As obvious as its name implies, this code implements linked list. The catch is, is that the input will be coming from a textfile. I used bufferedReader to read the whole file and StringTokenizer to read the individual lines in the files...
the code:
import java.io.*;
import java.util.*;
class Item
{
public Item( Object d, Item n )
{
data = d;
next = n;
}

public Object data;
public Item next;
}
class MyLinkedList
{
private Item head;
private Item tail;

//head is the first element in the list.
//tail is the last element in the list.
public MyLinkedList()
{
head = null;
tail = null;
}

public void addTail( Object data )
{
Item newTail = new Item( data, null );
if( head == null )
{
head = newTail;
tail = head;
}
else
{
tail.next = newTail;
tail = newTail;
}
}

public void addHead( Object data )
{
Item newHead = new Item( data, head );
if( head != null )
head = newHead;

else
{
head = newHead;
tail = head;
}
}

public void add( Object data, int index )
{
if( ( index == 0 ) || ( head == null ) )
addHead( data );
else
{
Item current = head;
while( ( current != null ) && ( index > 1 ) )
{
current = current.next;
index--;
}
if( current != null )
{
current.next = new Item( data, current.next );
if( current == tail )
tail = current.next;
}
}
}

public Object removeHead()
{
if( head == null )
return null;
Object data = head.data;
head = head.next;
return data;
}

public int find( Object data )
{
if( head == null )
return -1;
int index = 0;
Item current = head;
while( ( current != null ) && ( !current.data.equals( data ) ) )
{
index++;
current = current.next;
}
if( current == null )
return -1;
else
return index;
}

public Object remove( int index )
{
if( index == 0 )
return removeHead();
if( head == null )
return null;
Item current = head, previous = null;
while( ( current != null ) && ( index > 0 ) )
{
previous = current;
current = current.next;
index--;
}
if( current == null )
return null;
Object data = current.data;
previous.next = current.next;
return data;
}

public String toString()
{
if( head == null )
return "<empty>";
Item current = head;
String res = "{";
while( current != null ){
res = res + current.data;
if( current.next != null )
res += ",";
current = current.next;
}
res += "}";
return res;
}


public static void main( String args[] )
{

System.out.println("Enter file name:");
String fileName = SavitchIn.readLine();

try
{
BufferedReader inputStream =
new BufferedReader(new FileReader(fileName));


String line;
boolean done = false;
while(!done)// to get to the next line
{
line = inputStream.readLine();

StringTokenizer inputReader = new StringTokenizer(line);
//System.out.println(inputReader);
while(inputReader.hasMoreElements())//figures out every element in the line.
{

if (inputReader.nextElement().equals("d"))
{

Object x = inputReader.nextElement();

System.out.println("x = " + x);
System.out.println("element x is removed");

}
else if(inputReader.nextElement().equals("i"))

System.out.println("the element after the next is inserted");

else if(inputReader.nextElement().equals("ie"))
System.out.println("the next element is inserted at the end of the list");
else
{
boolean finish = true;
finish = inputReader.hasMoreElements();

}
line = inputStream.readLine();
}
done = true;

}
inputStream.close();
}

catch(FileNotFoundException e)
{
System.out.println(fileName + " not found!");
}

catch(IOException e)
{
System.out.println("Error reading" + fileName);
}


}
}
example input from a text file:
d 10 //remove 10
ie 2 //insert 2
the output:
Enter file name:
sample.txt
x = 10
element x is removed.
my problem:
my first while loop seemed to be incorrect, suppose to be, it would switch to every line but it wont switch, my second while loop worked though...as i said earlier, i got stuck with the loops that i can't complete my main...so can some genius help me please! my life is at stake...
20 years ago