Welcome to the forum 👋, Guest

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

  • PËRSHËNDETJE VIZITOR!

    Nëse ju shfaqet ky mesazh do të thotë se ju nuk jeni regjistruar akoma. Anëtarët e rregjistruar kanë privilegjin të marrin pjesë në tema të ndryshme si dhe të komunikojnë me anëtarët e tjerë. Bëhu pjesë e forumit Netedy.com duke u REGJISTRUAR këtu ose nëse ke një llogari KYCU. Komunikim alternative i ketij forumi me vajza dhe djem nga te gjithe trevat shqiptare? Hyr ne: CHAT SHQIP.

Funksioni: Intiger Partition nga 1 tek N

centos

ⓃⒺⓉⒺⒹⓎ.ⒸⓄⓂ
ANETAR ✓
Regjistruar më
Dhj 13, 2004
Mesazhe
39,815
Code:
#include <stdlib.h>
#include <stdio.h>
 
int NUM_OBJECTS = 20;
 
typedef struct{
    int* val;
    void* next;
} n_obj;
 
#define Q_INT malloc(sizeof(int))
#define Q_OBJ malloc(sizeof(n_obj))
#define Q_SEQ(x) calloc((x), sizeof(int))
 
int main()
{
    int clear_i;
    int i, left_i, cur_sz, cur_num;
    n_obj **cl;
    n_obj *temp;
    n_obj *cur_list;
    n_obj *cur_seq;
    
    cl = malloc(sizeof(n_obj*)*NUM_OBJECTS);
    
    for(i=0;i<NUM_OBJECTS;i++)
    {
        cl[i] = Q_OBJ;
        cl[i]->val = NULL;
        
        temp = Q_OBJ;
        temp->val = Q_SEQ(1);
        
        temp->val[0] = i + 1;
        
        temp->next = cl[i];
        cl[i] = temp;
        
        cur_list = cl[i];
        for(left_i=0; left_i<i; left_i++)
        {
            for(cur_seq=cl[left_i];cur_seq->val!=NULL;cur_seq=cur_seq->next)
            {               
                if(cur_seq->val[0]<=(i - left_i))
                {
                    temp = Q_OBJ;
                    temp->val = Q_SEQ(left_i + 3);
                    
                    temp->val[0] =  i - left_i;
                    
                    temp->next = cur_list->next;
                    cur_list->next = temp;
                    cur_list = temp;
                    
                    for(cur_num=0;cur_num<=left_i;cur_num++)
                        cur_list->val[cur_num+1] = cur_seq->val[cur_num];
                }
            }
        }
    }
    
    for(i = 0; i < NUM_OBJECTS; i++)
    {
        cur_sz = 0;
        printf(\"---------------------------\n\");
        for(cur_list = cl[i]; cur_list->val != NULL; cur_list = cur_list->next)
        {
            for(clear_i = 0; cur_list->val[clear_i] != 0; clear_i++)
            {
                printf(\"%d \", cur_list->val[clear_i]);
            }
            printf(\"\n\");
            cur_sz++;
        }
        printf(\"Number of partitions = %d\n\", cur_sz);
    
    }
    return 0;
}
 

Postime të reja

Theme customization system

You can customize some areas of the forum theme from this menu.

Choose the color combination according to your taste

Select Day/Night mode

You can use it by choosing the day and night modes that suit your style or needs.

Welcome to the forum 👋, Guest

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.