Lista jednokierunkowa usuwanie elementu

0

Witam niedługo będę miał projekt związany z listą jednokierunkową,więc chcę ją zrozumieć jak najlepiej.Pisze teraz funkcje do usuwania dowolnego elementu i lekko się zatrzymałem,wiec napisałem funkcje do usuwania pierwszego i ostatniego elementu wyglądają tak:
Czy są poprawne?Jakis pomysl jak napisac na usuwanie elementu podanego przez uzytkownika?Glownie chodzi mi o sytuacje nietypowe czyli lista jest pusta, ostatni element, pierwszy element,bo mniej więcej wiem jak usunąć element gdzieś ze środka,ale nie wiem ile specjalnych sytuacji tu może wystąpić i jak je ogarnąć.

 void usfirst(lista*&head)
{
	if (head == NULL)
	{
		cout << "LIsta pusta";
	}
	lista*temp;
	temp = head->next;
	head = temp;
}
void usost(lista*&head)
{
	if (head == NULL)
	{
		cout << "lista pusta";
	}
	lista*iterator;
	lista*prev = NULL;
	iterator = head;
	while (iterator->next != NULL)
	{
		prev = iterator;
		iterator = iterator->next;
	}
	delete iterator;
	prev->next = NULL;
}
0

Dawno nie pisałem w C++ ale może jakoś Ci pomoże

 #include <iostream>
using namespace std;

class obj{
    public:
        obj(void * value)
        {
            this->value = value;
        }
        obj *ReturnNext()
        {
            return Next;
        }
        obj * SetChild(obj *next)
        {
            Next = next;
            return Next;
        }
        obj * RunFor(int IndexForward)
        {
            obj * it = this;
            for(int n=0; n<IndexForward; ++n)
            {
                it = it->Next;
                if(it == nullptr)
                    return nullptr;
            }
            return it;
        }
        obj * RunFor(int IndexForward, obj *ParentPtr)
        {
            if(!ParentPtr)
                return this;
            obj * it = this;
            ParentPtr = nullptr;
            for(int n=0; n<IndexForward; ++n)
            {
                ParentPtr = it;
                it = it->Next;
                if(it == nullptr)
                    return nullptr;
            }
            return it;
        }

        bool EraseAt(int index)
        {
            obj * Parent = nullptr;
            obj * o = RunFor(index, Parent);

            if(o == nullptr)
                return false;
            else
            {
                if(Parent != nullptr)
                    Parent->Next = o->Next;
                //usuwasz element o;
            }
        }
    private:
        void * value = nullptr;
        obj *Next = nullptr;
};

int main()
{

}

1 użytkowników online, w tym zalogowanych: 0, gości: 1