Ross
Ross

Reputation: 3

Find the max subsequence of the given sequence of numbers (in a list)

void *max_subsequence(node *head){

    node *max=head;
    int count=0;
    int count1=0;
    int i;

    while(head!=NULL){
        count=0;
        while(head->num < head->next->num){
            count++;
            head=head->next;
        } 
        if(count > count1){
            count1=count;
        } 

        head=head->next;
        max=head;
    }  
}

This code doesn't compile and I don't know why. It should find the largest increasing subsequence of the given sequence stored in a list. Can anyone give me a hint?

typedef struct node1{
    int num;
    struct node1 *next;
    }node;

Upvotes: 0

Views: 74

Answers (1)

theKunz
theKunz

Reputation: 443

Change your while loops from node-> to head-> in both. Also be sure to heed Weather Vane's comment about a potential runtime error.

Upvotes: 1

Related Questions