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.

Page 2 of 2 FirstFirst 12
Results 26 to 39 of 39

Thread: request

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: request

    Most of the OPs are able to paste their code on the forum and use code tags. It can't be that hard if everyone can do it. Try again.
    type: [code]
    then paste the code
    then type: [/code]
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: request

    import java.util.Random;
     
    public class DLinkedList {
     
    private class Node {
    int item;
    Node next;
    Node previous;
     
    }
     
    private Node head = null;
     
     
    public void Insert(int item) {
    if( head==null){
    head = new Node();
    head.item = item;
    head.next = head;
    head.previous = head;
    }else{
    Node newNode = new Node();
    newNode.item = item;
    Node tail = head.previous;
    tail.next = newNode;
    newNode.previous = tail;
    newNode.next = head;
    head.previous = newNode;
    }
    }
     
     
    public boolean insertAfter(int key, int item) {
       Node first=null;
      Node last=null;
        Node current = first;
      //  System.out.println( key);
        while (current.item !=key) {
     
          current = current.next;
          if (current == null){
            return false;
          }
        }
       Node newNode = new Node();
     
        if (current == last) {
         newNode.next = null;
         last = newNode;
     } 
        else {
          newNode.next = current.next;
     
          current.next.previous = newNode;
        }
        newNode.previous = current;
        current.next = newNode;
        return true;
     }
     
     
    public int count() {
    if( head==null){
    return 0;
    }
    Node node = head;
    int count = 0;
    while( true){
    node = node.next;
    if( node!=head){
    count++;
    }else{
    break;
    }
    }
    if( head==null){
    System.out.println( " List is empty");
    }else{
    //Node node = head.previous.next;
        int x=1;
    while(x <= count/2){
    node = node.next;
    x++;
    if( node!=head){
    System.out.print( node.item + " ");
    }else{
    break;
    }
    }
    //System.out.println();
    }
    return count;
    }
     
     
     
    //public int getLargest() {
    //number below is the bottom negative range of integer
    //int largest = -2147483648;
    //if( head==null){
    //return largest;
    //}
    //Node node = head;
    //largest = head.item;
    //while( true){
    //node = node.next;
    //if( node!=head){
    //if( node.item > largest){
    //largest = node.item;
    //}
    //}else{
    //break;
    //}
    //}
    //return largest;
    //}
     
    public void print(){
    if( head==null){
    System.out.println( " List is empty");
    }else{
    Node node = head.previous.next;
    while( true){
    node = node.next;
    if( node!=head){
    System.out.print( node.item + " ");
    }else{
    break;
    }
    }
    System.out.println();
    }
    }
     
     
     
    public static void main( String[] args){
    DLinkedList list = new DLinkedList();
    //Random random = new Random();
     
    //randomly add between 5 to 14 numbers to list
    for(int i=1; i<10; i++){
    //random insert numbers between 0 and 100, not including 100
    list.Insert(i);
    }
     
    list.print();
    System.out.println( "the middle of list after item no. " + list.count()/2 );
    //System.out.println( "The larget number in the list is " + list.getLargest());
    list.insertAfter(5, 77);
    list.print();
    }
    }


    --- Update ---

    i post it again.i did like this every time but i do not know where the problem

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: request

    I have no idea what your problem is.
    Why is the formatting for the insertAfter() method good and the rest of the code is not formatted?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: request

    can you copy it and paste in your IDE??

  5. #30
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: request

    I will copy it when it is properly formatted.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #32
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: request

    look!! this is the capture of the code

  8. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: request

    I'm waiting for properly formatted code to be posted.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #34
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: request

    it is formatted!!

    --- Update ---

    ok thank you..i think you are annoying from me

  10. #35
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: request

    where? I can't see where any of the posted code is properly formatted.
    What is the post# where it's formatted? except for the insertAfter() method.

    ok thank you..i think you are annoying from me
    If you don't want to format the source code, let me know and I will leave you for someone else that doesn't care if the code they work with is formatted or not.
    Let me know.
    If you don't understand my answer, don't ignore it, ask a question.

  11. The Following User Says Thank You to Norm For This Useful Post:

    aegr (March 24th, 2013)

  12. #36
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: request

    Quote Originally Posted by aegr View Post
    it is formatted!!

    --- Update ---

    ok thank you..i think you are annoying from me
    He's trying to help you if you let him. He has much more patience than most of us, trust me, and it is needed in this thread to be sure. Myself, I'd be much more blunt with you, and so I will keep out of this thread except for this post.

  13. #37
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: request

    i type
     and paste the code and type
    ,formate the size
    this is not the first time i post code in forums!!

    --- Update ---

    thank you..for your patiance..you see the captures?

    --- Update ---

    import java.util.Random;
     
    public class DLinkedList {
     
    private class Node {
    int item;
    Node next;
    Node previous;
     
    }
     
    private Node head = null;
     
     
    public void Insert(int item) {
    if( head==null){
    head = new Node();
    head.item = item;
    head.next = head;
    head.previous = head;
    }else{
    Node newNode = new Node();
    newNode.item = item;
    Node tail = head.previous;
    tail.next = newNode;
    newNode.previous = tail;
    newNode.next = head;
    head.previous = newNode;
    }
    }
     
     
    public boolean insertAfter(int key, int item) {
       Node first=null;
      Node last=null;
        Node current = first;
      //  System.out.println( key);
        while (current.item !=key) {
     
          current = current.next;
          if (current == null){
            return false;
          }
        }
       Node newNode = new Node();
     
        if (current == last) {
         newNode.next = null;
         last = newNode;
     } 
        else {
          newNode.next = current.next;
     
          current.next.previous = newNode;
        }
        newNode.previous = current;
        current.next = newNode;
        return true;
     }
     
     
    public int count() {
    if( head==null){
    return 0;
    }
    Node node = head;
    int count = 0;
    while( true){
    node = node.next;
    if( node!=head){
    count++;
    }else{
    break;
    }
    }
    if( head==null){
    System.out.println( " List is empty");
    }else{
    //Node node = head.previous.next;
        int x=1;
    while(x <= count/2){
    node = node.next;
    x++;
    if( node!=head){
    System.out.print( node.item + " ");
    }else{
    break;
    }
    }
    //System.out.println();
    }
    return count;
    }
     
     
     
    //public int getLargest() {
    //number below is the bottom negative range of integer
    //int largest = -2147483648;
    //if( head==null){
    //return largest;
    //}
    //Node node = head;
    //largest = head.item;
    //while( true){
    //node = node.next;
    //if( node!=head){
    //if( node.item > largest){
    //largest = node.item;
    //}
    //}else{
    //break;
    //}
    //}
    //return largest;
    //}
     
    public void print(){
    if( head==null){
    System.out.println( " List is empty");
    }else{
    Node node = head.previous.next;
    while( true){
    node = node.next;
    if( node!=head){
    System.out.print( node.item + " ");
    }else{
    break;
    }
    }
    System.out.println();
    }
    }
     
     
     
    public static void main( String[] args){
    DLinkedList list = new DLinkedList();
    //Random random = new Random();
     
    //randomly add between 5 to 14 numbers to list
    for(int i=1; i<10; i++){
    //random insert numbers between 0 and 100, not including 100
    list.Insert(i);
    }
     
    list.print();
    System.out.println( "the middle of list after item no. " + list.count()/2 );
    //System.out.println( "The larget number in the list is " + list.getLargest());
    list.insertAfter(5, 77);
    list.print();
    }
    }


    --- Update ---

    i will be crazy!!!what is the problem

  14. #38
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: request

    Quote Originally Posted by aegr View Post
    i type
     and paste the code and type
    ,formate the size
    this is not the first time i post code in forums!!

    --- Update ---

    thank you..for your patiance..you see the captures?
    We see your posted code, and while it has *some* formatting, it is not *well formatted* since you are not using indentation in a uniform and standard way.

    <blunt>Look. You are asking for free help from volunteers. Is it really asking too much of you to put in just a little effort to post *well formatted* code so that we can more easily read your code and understand it? </blunt>

  15. The Following User Says Thank You to curmudgeon For This Useful Post:

    aegr (March 24th, 2013)

  16. #39
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: request

    thank you for all

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Http Request
    By nillson in forum Loops & Control Statements
    Replies: 3
    Last Post: March 20th, 2013, 06:42 PM
  2. xml request in java code
    By ridg18 in forum Java Theory & Questions
    Replies: 10
    Last Post: August 9th, 2012, 08:39 AM
  3. Clueless on request.getContextPath()
    By ram.java in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 29th, 2011, 12:07 PM