Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Data Structure

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Data Structure

    1-,

    Hi all,
    can anyone help me with this? i need to know the java progrmmae for it ..





    _write a program that determines whether an input string is palindrome;that is whether it can be read the same way forward & backward .at each point you can read only one character of the input string;do not use an array to first store this string and then analyze it(expect,possibly,in a stack implementation).consider using multiple stack




    _write a recursive method gcd(n,m)that return the greatest common dividor of two integer n & m





    thanx in advance .


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,235
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Data Structure

    What have you tried? Dumping homework questions is not a great way to get advice as no one is going to do these for you. Rather, attempting the problems and showing what you've done, describing where you are stuck, what errors you receive is a much better alternative. Suggested reading: How To Ask Questions The Smart Way

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Data Structure

    Quote Originally Posted by copeg View Post
    What have you tried? Dumping homework questions is not a great way to get advice as no one is going to do these for you. Rather, attempting the problems and showing what you've done, describing where you are stuck, what errors you receive is a much better alternative. Suggested reading: How To Ask Questions The Smart Way


    i dono how to start or what to do for first step?
    can u answer this Q?

  4. #4
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,235
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Data Structure

    i dono how to start or what to do for first step?
    can u answer this Q?
    No, I won't do your homework for you (and according the forum policy, anyone that does may have their posts edited to remove solutions). Break the problem down to the requirements and look through the tutorials: The Java™ Tutorials .

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Data Structure

    public static void main(String[] args)
    {	
    String input = "";
    String str = "";
    Scanner scan = new Scanner(System.in);
    System.out.print("Enter a string: ");
    while(true)
    {
     
    str = scan.nextLine();
    if(str.length() == 0)
    break;
    if(str.length() > 1)
    {
    System.out.println("Only one character");
    str= scan.nextLine();
    }
     
    input+= str;
    }
     
    Palindrome result = new Palindrome(input);
    if(result.isPalindrome())
    System.out.println("This is a Palindrome string");
    else
    System.out.println("This is not a Palindrome string"); 
    }


    * so is that right code?
    Last edited by helloworld922; July 8th, 2011 at 02:26 PM.

  6. #6
    Junior Member
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Data Structure

    /* Recursive Function*/
    gcd(int n,int m)
    	{ if(m<=n && n%m == 0)
    	   return m;
    	  if(n < m)
    	   return gcd(m,n);
    	  else
    	   return gcd(m,n%m);
    	 }
    *this for the recursive ? its right too or not ?
    Last edited by helloworld922; July 8th, 2011 at 02:27 PM.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Data Structure

    Your assignment description says, you should use multiple stacks so first get the idea about stack, what is stack, how to implement stack and blah blah....
    Then try using stack and you can easily solve this by maximum of two stacks.

  8. #8
    Junior Member
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Data Structure

    import java.util.*;
    public class CheckPalindrome{
    public static void main(String[]args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter String: ");
    String st=input.next();
    String str[]=st.split("");
    String reversedSt="";
    for(int i=str.length-1;i>=0;i--){
    reversedSt+=str[i];
    }
    if(st.equalsIgnoreCase(reversedSt)){
    System.out.println("String is palindrome");
    }
    else{
    System.out.println("String is not palindrome");
    }
    }
    }




    how can i write this code using stacks "java" ?
    Last edited by Faha; May 3rd, 2011 at 01:48 PM.

  9. #9
    Junior Member
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Data Structure

    Data Structure means to way of storing data in different manner. There are many types of Data Structures. Like linear ,non-linear, hash tree, binary tree, etc. Data Structures in programming are very useful. There are many DS like Stack, Queue, Link List, Circular Link List, Doubly Link List.

  10. #10
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Data Structure

    Don't bump the old threads

Similar Threads

  1. What is the fastest and most memory-efficient data structure?
    By aussiemcgr in forum Collections and Generics
    Replies: 5
    Last Post: October 11th, 2012, 03:48 PM
  2. data structure assignment .. help me : |
    By Noni in forum Object Oriented Programming
    Replies: 4
    Last Post: March 21st, 2011, 10:33 AM
  3. HI can some one tell me the size of the below structure.
    By sucheth13 in forum Java Native Interface
    Replies: 1
    Last Post: March 11th, 2011, 02:08 AM
  4. Data Structure for ordered binay tree
    By wash in forum Algorithms & Recursion
    Replies: 0
    Last Post: April 23rd, 2010, 05:31 PM
  5. .xls data structure
    By helloworld922 in forum JDBC & Databases
    Replies: 3
    Last Post: August 20th, 2009, 07:12 PM

Tags for this Thread