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.119 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.118 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.117 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.116 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.115 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.114 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.113 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.111 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.110 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.109 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.108 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.107 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.106 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.105 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.104 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.103 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.102 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.101 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.100 tracks/c/exercises/sublist/src/example.c
trackler-2.2.1.99 tracks/c/exercises/sublist/src/example.c