Thread: Polynomials: Array of pointers to linked lists?

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    25

    Polynomials: Array of pointers to linked lists?

    Right now, I have a polynomial stored as a linked list (struct with element for coeff, element for exponent).

    For multiple polynomials, there needs to be a linked list created for each polynomial.

    How exactly would I create an array of pointers to these linked lists?

    Would I just create an array like
    Code:
    int *Polynomials[MAX];
    Here's my linked list code:
    Code:
    /*Building of Linked List */
    	m = (struct node*)malloc(sizeof(struct node));
    
    	if (first == NULL) 
    	
    	{
    		first = m;
    		
    	
    
    	}
    
    	if (last == NULL) 
    
    	{
    
        last = m ;
    
    	}
    
    	else
    
    	{
    	last -> next = m;
    	last = m; 
    
    	}
    
    	
    	last -> coeff = Coefficient;
    	last -> power = Exponent; 
    	last -> next =  NULL;
    Thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It wouldn't be an integer array. It would be an array of whatever your structures are called.
    Code:
    struct poly *array[ X ];
    Then you just access whatever spot in the array like you would any other array:
    Code:
    array[ 3 ] = somepolyptr;
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yeah, except it would be
    Code:
    node *polynomials[MAX];
    polynomials[0] is the head of a list. and polynomials[1] is the head of another list.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with pointers and linked lists
    By Christine in forum C Programming
    Replies: 3
    Last Post: 02-13-2011, 11:21 AM
  2. Help with linked lists/ pointers
    By anything25 in forum C Programming
    Replies: 14
    Last Post: 06-26-2009, 02:41 PM
  3. Linked Lists & Pointers
    By fkheng in forum C Programming
    Replies: 4
    Last Post: 06-10-2003, 07:26 AM
  4. Polynomials with linked Lists
    By shaheedpak in forum C++ Programming
    Replies: 0
    Last Post: 09-26-2001, 11:10 AM
  5. Generating Polynomials using Linked Lists
    By shaheedpak in forum C++ Programming
    Replies: 0
    Last Post: 09-25-2001, 01:22 PM