ListNode *rotateRight(ListNode *head, int k) {
        if (head == NULL || head->next == NULL)
            return head;

        ListNode*   original_tail = NULL;
        int     size = getListSize(head, original_tail);

        k = k%size;
        if (k == 0)
            return  head;

        k = size - k;
        ListNode*   newTail = getNodeByIndex(head, k - 1);
        assert(newTail && newTail->next);

        original_tail->next = head;
        head = newTail->next;
        newTail->next = NULL;
        return head;
    }
Пример #2
0
int main(int argc, char const *argv[])
{

	ListaLigada* l = newListaLigada();
	char f = 'f';
	char c = 'c';
	Teste* n = (Teste*)malloc(sizeof(Teste));
	n->i=5;
	n->c='p';
	addNode(l, (void*)&f, sizeof(char));
	addNode(l, (void*)&c, sizeof(char));
	addNode(l, (void*)n, sizeof(Teste));
	//remNode(l, 1);
	remNode(l, 0);
	remNode(l, 0);
	//printListaLigada(l);
	Teste* f2 = (Teste*)getNodeByIndex(l, 0);
	printf("-----------------------------\n");
	printf("%i, %c", f2->i, f2->c);
	freeListaLigada(l);
	free(f2);
	free(n);
	return 0;
}