Sha256: bd6c015cdb6273eb7f85c2cb8eb51a7c3712471473d8275a99f9f636826d4772

Contents?: true

Size: 1.97 KB

Versions: 117

Compression:

Stored size: 1.97 KB

Contents

#include "sublist.h"
#include <stdbool.h>
#include <string.h>

static bool is_equal(int *list_to_compare, int *base_list,
                     size_t list_to_compare_element_count,
                     size_t base_list_element_count)
{
   return (list_to_compare_element_count == base_list_element_count
           && !memcmp(list_to_compare, base_list,
                      list_to_compare_element_count * sizeof(int)));
}

static bool is_sublist(int *list_to_compare, int *base_list,
                       size_t list_to_compare_element_count,
                       size_t base_list_element_count)
{
   int i;
   int loop_end = (base_list_element_count - list_to_compare_element_count);

   if (list_to_compare_element_count > base_list_element_count) {
      return false;
   }

   for (i = 0; i <= loop_end; i++) {
      if (!memcmp
          (list_to_compare, &base_list[i],
           list_to_compare_element_count * sizeof(int))) {
         return true;
      }
   }

   return false;
}

static bool is_superlist(int *list_to_compare, int *base_list,
                         size_t list_to_compare_element_count,
                         size_t base_list_element_count)
{
   return is_sublist(base_list, list_to_compare, base_list_element_count,
                     list_to_compare_element_count);
}

comparison_result_t check_lists(int *list_to_compare, int *base_list,
                                size_t list_to_compare_element_count,
                                size_t base_list_element_count)
{
   if (is_equal
       (list_to_compare, base_list, list_to_compare_element_count,
        base_list_element_count)) {
      return EQUAL;
   } else if (is_sublist
              (list_to_compare, base_list, list_to_compare_element_count,
               base_list_element_count)) {
      return SUBLIST;
   } else if (is_superlist
              (list_to_compare, base_list, list_to_compare_element_count,
               base_list_element_count)) {
      return SUPERLIST;
   }

   return UNEQUAL;
}

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.179 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.178 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.177 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.176 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.175 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.174 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.173 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.172 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.171 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.170 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.169 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.167 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.166 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.165 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.164 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.163 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.162 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.161 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.160 tracks/c/exercises/sublist/src/example.c