Exemplo n.º 1
0
void fill_list(ForwardList &list, int number){ //заполняем список
    if (list.getHead() == 0) {
        list.push_back(list.getHead());
    }
    for(int i = 0; ( i < list.max_size() - 1) && i < number; ++i)
        list.push_back(list.end(), list.order_number() + 1);
}
Exemplo n.º 2
0
void delete_every_offset(ForwardList &list, int offset){
    int counter = 0;
    ForwardList::node *node = list.getHead();
    for (int i = 0; i < offset - 2; ++i) { //при первом удалении нужно пройти на 1 указатель меньше
        node = node -> next;
    }
    list.remove_after(node);
    for (; list.getHead()->next != list.getHead(); node = node->next) {
        if (counter == offset - 1) {
            list.remove_after(node);
            counter = 0;
        }
        counter++;
    }
    
    
}
Exemplo n.º 3
0
int main(int argc, const char * argv[])
{
    int size = 0; //N
    scanf("%d", &size);
    int offset = 0; //k
    scanf("%d", &offset);
    ForwardList* list = new ForwardList(size);
    fill_list(*list, size);
    delete_every_offset(*list, offset);
    printf("%d", list->getHead()->numberOfNode);
    return 0;
}