How to ask for help with your code

We will post new feature updates here
Post Reply
dbremmen@gmail.com
Posts: 63
Joined: Sun Jan 07, 2018 6:30 pm

How to ask for help with your code

Post by dbremmen@gmail.com » Mon Feb 26, 2018 11:42 am

Dear Browxy Enthusiasts,

To be able to the Browxy community to help you effectively please follow this guidelines

a) Use a meaningful subject like "Java - Compilation Issue with Palindrome problem" or "Java - Issue using to static methods"

b) Explain clearly the problem

c) Paste your code URL in the post

1) Right Click on your project, select Edit Project Properties and uncheck the private checkbox (this is to allow anybody to see your program) and click "Save"
2) Right click on your project and click "Get Url", this will give you the URL to share your program
3) Paste the URL in the post

d) Paste your code in the post using code tags
codeTagsButton.png
codeTagsButton.png (10.13 KiB) Viewed 38817 times
Paste the code of each file and surround it with code tags (use the button </>).
Also add the names of the files in bold before each one of them

e) Preview your post before posting to see If it is nice and well formatted

Example

Subject How to write then Main method for a Palindrome Problem

Description I want to print a list and determine if it is palindrome
I have 2 methods: printList & isPalindrome, but I don't know hot to execute them in the main
please help

Code Url http://www.beta.browxy.com#ALIEN_10640

IntList.java

Code: Select all

public class IntList{
    private IntNode _head;
    
    public IntList() {
        _head = null;
    }
    public IntList (IntNode node){
        _head = node;
    }
    public boolean isPalindrome(){
        int len,count;
        IntNode p,prev;
        //No.1 - find the lists length
        for(p = _head, len = 0; p != null; p= p.getNext() )
        len++;
        //list with one element is palindrom
        if(len == 1) {
          System.out.println("len = 1");
          return true;
        }
        //No.2 - find the middle element in the list
        //we use two pointers so we won't loose the end of the list.
        p = _head;
        prev = null ;
        count = 0;
        while(count < len/2)
        {
            prev = p;
            p = p.getNext();
            count++;
        }
        //now prev points to the last element in the first half
        // p points to the middle element
        //No.3 - seperate the two halfs
        prev.setNext(null);
        
        
        //No.4 - reverse the list that starts  with p
        //(we'll write a method that does it)
        p = reverseList(p);
        
        //No.5 - run from both sides and look for unmatched nums
        
        IntNode first ,second ;
        first = _head;
        second = p;
        while(first != null)
        {
            System.out.println("checking: " + first.getValue() + " against: " + second.getValue());
            if(first.getValue() != second.getValue())
            return false;
            first = first.getNext();
            second = second.getNext();
        }
        //if we arrived this line,the list is palindrome
        return true;
    
    
    
}
/**
 * Reverse the given list,and return its new head.
 */
 private static IntNode reverseList(IntNode h){
     //current represnts the element to be reversed
     //rev is the reversed list's head
     IntNode current,rev;
     current = h;
     rev = null ;
     while(h != null)
     {
         h = h.getNext();
         current.setNext(rev);
         rev = current ;
         current = h;
     }
         return rev;
     }
 
 public void printList(){
     IntNode temp = _head;
     while(temp != null)
     {
         System.out.print(temp.getValue() + " --> ");
         temp = temp.getNext();
     }
     System.out.println(" null");
 }
}


IntNode.java

Code: Select all

public class IntNode {
    private int _value;
    private IntNode _next;
    
    public IntNode(int val , IntNode n){
        _value = val;
        _next = n;
    }
    
    public int getValue(){
        return _value;
    }
    public IntNode getNext(){
        return _next;
    }
    public void setValue(int v){
        _value = v;
    }
    public void setNext(IntNode node){
        _next = node;
    }
}


Post Reply