linked list fill the gaps question..

This is a discussion on linked list fill the gaps question.. within the C Programming forums, part of the General Programming Boards category; i have a struct Code: typedef struct item{ int number; //the number int occur; // the number of ocuurances of ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    linked list fill the gaps question..

    i have a struct
    Code:
    typedef struct item{
    int number;  //the number  
    int occur;    // the number of ocuurances of this number
    	struct item *next;
    }item;
    i need to compete the gaps of the following structure
    so it will reduse the duplicates of a certain item in the original list
    and puts the total number of the occurances of a item into its item.number struct.
    for example
    http://i39.tinypic.com/1z3016p.gif
    Code:
    void reduce(item *head){
    	item* temp;
    	int count =  ?? 1 ??;
    
    	if ??  2  ?? ;
    
    	while(??  3  ??)
    		if( ?? 4 ?? ){
    			??  5  ??;
    			  ?? 6 ??;
    			??   7 ?? ;
    			count++;
    		}
    		else{
    			head->occur = count;
    			?? 8 ?? ;
    			?? 9 ?? ;
    		}
    	?? 10 ?? ;
    	
    }
    i tried to fill some but i can see what each block of the given structure should do in general
    Code:
    void reduce(item *head){
    	item* temp;
    	int count =  0;
    
    	if (!head) return;
    
    	while(temp)
    		if(head->number==head->next->number ){
    			temp=head->next;
    			  head->next=head->next->next;
    			free(temp) ;
    			count++;
    		}
    		else{
    			head->occur = count;
    			head=head->next;
    			?? 9 ?? ;
    		}
    	?? 10 ?? ;
    	
    }


    i tried to fill some but i can see what each block of the given structure should do in general

  2. #2
    Registered User
    Join Date
    Jul 2009
    Posts
    40
    Quote Originally Posted by transgalactic2 View Post
    Code:
    void reduce(item *head){
    	item* temp;
    	int count =  0;
    
    	if (!head) return;
    
    	while(temp)  { 
    		if(head->number==head->next->number ){
    			temp=head->next;
    			  head->next=head->next->next;
    			free(temp) ;
    			count++;
    		}
    		else{
    			head->occur = count;
    			head=head->next;
    			?? 9 ?? ;
    		}
    	}?? 10 ?? ;
    	
    }
    Should you be closing it in a while block?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No, he should stop posting his homework without even trying anything!

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list question
    By brb9412 in forum C Programming
    Replies: 16
    Last Post: 01-04-2009, 04:05 PM
  2. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 09:04 PM
  3. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  4. How to use Linked List?
    By MKashlev in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 08:11 AM
  5. Array, Linked List, or Binary Tree?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 01-05-2002, 10:07 PM

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