Array of nodes

This is a discussion on Array of nodes within the C++ Programming forums, part of the General Programming Boards category; Hello I am clueless on this one...so I will need alot of help, or if you are willing straight code. ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    85

    Array of nodes

    Hello

    I am clueless on this one...so I will need alot of help, or if you are willing straight code.

    I have an array of size 10.

    I need to take a linked list and iterate through it. In the array is a structure. I get a digit from structure.d_pop. Based on this digit I need to place that node into the array Eg.

    Digit 0 goes to the list in array[0]
    Digit q goes into the list in array [1]

    ... and so on.


    I do not know how to go about placing these nodes int the array, sinc the array will only hold the address of th first item in the list.

    I need to initialize and then do it. Here is the code I have thus far

    Code:
    
    
    struct info{
    
    	string fips;
    	string d_name;
    	string r_code;
    	int d_pop;
    	int sd_enrol;
    	int st_need;
    };
    struct node
      {  
         info node_struct; 
         node *nxt; 
    };
    
    
    
    
    
    
    
    void bucket_sort(int digit)
    {
         node buckets[10];
         node *temp;
         temp = start_ptr;
         int i;
         
    do
      {  if (temp == NULL)
         {
         }
         else
         {
             if(get_digit(temp->node_struct,digit) == 0)
             {
             
             }  
             
             temp = temp->nxt;
         }
      }while (temp != NULL);
    
         
         
          
              
    }

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    sorry digit q should be digit 1 above

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    *****bump*******

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    >> sorry digit q should be digit 1 above
    You can edit your posts to make changes like that.

    >> *****bump*******
    I'm not sure how much a bump will help when the thread is already third on the list.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    Here is where I am...the zero place repeates though

    Code:
    //******************************************************************BUCKET SORT
    void bucket_sort(int digit)
    {
         node *buckets[10];
         node *temp, *temp2;
         temp = start_ptr;
         int i;
         int digit_num;
         
         for(i=0; i<10; i++)
         {
                  buckets[i] = NULL;
         }
         
    do
      {  if (temp == NULL)
         {
         }
         else
         {
             digit_num = get_digit(temp->node_struct,digit);
             //cout << "Digit = " << digit_num << endl;
             if(digit_num == 0)
             {
                  if(buckets[0] == NULL)
                  {
                  cout << " A ZERO DIGIT" << endl;
                  buckets[0] = temp;
                  }
                  else
                  {
                      buckets[0]->nxt = temp;
                  }
             }
             else if(digit_num == 1)
             {
             if(buckets[1] == NULL)
                  {
                  cout << " A ONE DIGIT" << endl;
                  buckets[1] = temp;
                  }
                  else
                  {
                      buckets[1]->nxt = temp;
                  }
             }
             else if(digit_num == 2)
             {
                  if(buckets[2] == NULL)
                  {
                  cout << " A TWO DIGIT" << endl;
                  buckets[2] = temp;
                  }
                  else
                  {
                      buckets[2]->nxt = temp;
                  }
             }
             else if(digit_num == 3)
             {
                  if(buckets[3] == NULL)
                  {
                  cout << " A THREE DIGIT" << endl;
                  buckets[3] = temp;
                  }
                  else
                  {
                      buckets[3]->nxt = temp;
                  }
             }
             else if(digit_num == 4)
             {
                  if(buckets[4] == NULL)
                  {
                  cout << " A FOUR DIGIT" << endl;
                  buckets[4] = temp;
                  }
                  else
                  {
                      buckets[4]->nxt = temp;
                  }
             }
             else if(digit_num == 5)
             {
                 if(buckets[5] == NULL)
                  {
                  cout << " A FIVE DIGIT" << endl;
                  buckets[5] = temp;
                  }
                  else
                  {
                      buckets[5]->nxt = temp;
                  }
             
             }  
             else if(digit_num == 6)
             {
                 if(buckets[6] == NULL)
                  {
                  cout << " A SIX DIGIT" << endl;
                  buckets[6] = temp;
                  }
                  else
                  {
                      buckets[6]->nxt = temp;
                  }
             
             }
             else if(digit_num == 7)
             {
                 if(buckets[7] == NULL)
                  {
                  cout << " A SEVEN DIGIT" << endl;
                  buckets[7] = temp;
                  }
                  else
                  {
                      buckets[7]->nxt = temp;
                  }
             }
             else if(digit_num == 8)
             {
                 if(buckets[8] == NULL)
                  {
                  cout << " A EIGHT DIGIT" << endl;
                  buckets[8] = temp;
                  }
                  else
                  {
                      buckets[8]->nxt = temp;
                  }
             }
             else if(digit_num == 9)
             {
                 if(buckets[9] == NULL)
                  {
                  cout << " A NINE DIGIT" << endl;
                  buckets[9] = temp;
                  }
                  else
                  {
                      buckets[9]->nxt = temp;
                  }
             }
             
         temp2 = temp->nxt;
         temp->nxt = NULL;
         temp = temp2;
         }
      }while (temp != NULL);
    
         
         
          
              
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 01:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21