Why can't delete the right node? : <p>i have some code here. I'm using linked list in this code. We can add note, displas it and also delete. The problem occur when i want to delete something.
1. create one node, then try to delete it. It can detect and delete the node.
2. create two node, then i try to delete the 1st one. but it delete the second.
I really run out of idea right now. Hopefully anyone can help me. Thank you</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string.h&gt;
using namespace std;
const int SIZE = 10;

//1st class
class SportShoe  {
    private:
        struct nodeSport {
            int ShoeID;
            char BrandShoe[SIZE]; 
            char TypeShoe[SIZE];
            char ColourShoe[SIZE];
            int SizeShoe;
            float PriceShoe; 
            nodeSport *last;
        };
        nodeSport *first = NULL; 

    public:
        int MenuSportShoe();
        void AddSportShoe();
        void DisplaySportShoe();
        void DeleteSportShoe();
        static void ExitSportShoe();
   };

 //2nd class
class HighHeel  {
    private:
        struct nodeHeel {
            int ProductCode;
            char BrandHeel[SIZE]; 
            char MaterialHeel[SIZE];
            char ColourHeel[SIZE];
            int HeightHeel;
            float PriceHeel; 
            nodeHeel *next; 
        };
    nodeHeel *start = NULL; 

    public:
        int MenuHighHeel();
        void AddHighHeel();
        void DisplayHighHeel();
        void DeleteHighHeel();
        static void ExitHighHeel()
        {
            SportShoe::ExitSportShoe();
        }
 };

int SportShoe::MenuSportShoe() {
    int OptionSportShoe = 0;

    cout &lt;&lt; endl;
    cout &lt;&lt; "&gt;&gt; Please select from the menu below &lt;&lt;" &lt;&lt; endl;
    cout &lt;&lt; ":: 1 :: Add item to shoe list" &lt;&lt; endl;
    cout &lt;&lt; ":: 2 :: Display shoes list" &lt;&lt; endl;
    cout &lt;&lt; ":: 3 :: Delete item from the list" &lt;&lt; endl;
    cout &lt;&lt; ":: 4 :: Back" &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; OptionSportShoe;

    while (OptionSportShoe == 1){
        AddSportShoe();
    }

    while (OptionSportShoe == 2){
        DisplaySportShoe();
    }

    while (OptionSportShoe == 3){
        DeleteSportShoe();
    }

    while (OptionSportShoe == 4){
        ExitSportShoe();
    }

    return 0;
 }

 int HighHeel::MenuHighHeel() {
    int OptionHighHeel = 0;

    cout &lt;&lt; endl;
    cout &lt;&lt; "&gt;&gt; Please select from the menu below &lt;&lt;" &lt;&lt; endl;
    cout &lt;&lt; ":: 1 :: Add item to the Heel List" &lt;&lt; endl;
    cout &lt;&lt; ":: 2 :: Display the Heel List" &lt;&lt; endl;
    cout &lt;&lt; ":: 3 :: Delete item from the list" &lt;&lt; endl;
    cout &lt;&lt; ":: 4 :: Back" &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; OptionHighHeel;

    while (OptionHighHeel == 1){
        AddHighHeel();
    }

    while (OptionHighHeel == 2){
        DisplayHighHeel();
    }

    while (OptionHighHeel == 3){
        DeleteHighHeel();
    }

    while (OptionHighHeel == 4){
        SportShoe::ExitSportShoe();
    }

    return 0;
  }

 void SportShoe::AddSportShoe() {   
    nodeSport *tempShoe1, *tempShoe2; 

    tempShoe1 = new nodeSport;
    cout &lt;&lt; "Sport Shoe Section." &lt;&lt; endl;
    cout &lt;&lt; "Please enter the Shoe ID : (eg. 43210) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; tempShoe1-&gt;ShoeID;

    cout &lt;&lt; "Please enter the Shoe Brand: (eg. Adidas) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin.sync();
    cin.getline(tempShoe1-&gt;BrandShoe,SIZE);

    cout &lt;&lt; "Please enter the Shoe Type : (eg. Running) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin.sync();
    cin.getline(tempShoe1-&gt;TypeShoe,SIZE);

    cout &lt;&lt; "What is the Shoe Colour : (eg. Grey) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin.sync();
    cin.getline(tempShoe1-&gt;ColourShoe,SIZE);

    cout &lt;&lt; "Please enter Shoe Size : (eg. 9) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; tempShoe1-&gt;SizeShoe; 

    cout &lt;&lt; "Please enter the price of the Shoe : (eg. RM123.45) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; RM ";
    cin &gt;&gt; tempShoe1-&gt;PriceShoe;


    tempShoe1-&gt;last = NULL;  


    if (first == NULL)  
        first = tempShoe1;
    else  
    {
        tempShoe2 = first; 
        while (tempShoe2-&gt;last != NULL) 
            tempShoe2 = tempShoe2-&gt;last;

        tempShoe2-&gt;last = tempShoe1;
    }

    system("PAUSE");
    MenuSportShoe();
 }

 void HighHeel::AddHighHeel() { 
    nodeHeel *tempHeel1, *tempHeel2; 

    tempHeel1 = new nodeHeel;
    cout &lt;&lt; "Heel Section." &lt;&lt; endl;
    cout &lt;&lt; "Please enter Heel Code : (eg. 98765) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; tempHeel1-&gt;ProductCode;

    cout &lt;&lt; "Please enter Heel Brand: (eg. Gucci) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin.sync();
    cin.getline(tempHeel1-&gt;BrandHeel,SIZE);

    cout &lt;&lt; "Please enter Heel Material : (eg. Leather) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin.sync();
    cin.getline(tempHeel1-&gt;MaterialHeel,SIZE);

    cout &lt;&lt; "What is the Heel Colour : (eg. Red) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin.sync();
    cin.getline(tempHeel1-&gt;ColourHeel,SIZE);

    cout &lt;&lt; "Please enter Heel Height (cm) : (eg. 2.25) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; tempHeel1-&gt;HeightHeel; 

    cout &lt;&lt; "Please enter the Heel Price : (eg. RM123.45) " &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; RM ";
    cin &gt;&gt; tempHeel1-&gt;PriceHeel;

    tempHeel1-&gt;next = NULL;  


    if (start == NULL)  
        start = tempHeel1;
    else  
    {
        tempHeel2 = start; 
        while (tempHeel2-&gt;next != NULL) 
            tempHeel2 = tempHeel2-&gt;next;

        tempHeel2-&gt;next = tempHeel1;
    }

    system("PAUSE");
    MenuHighHeel();
}

void SportShoe::DisplaySportShoe() {
    nodeSport *tempShoe1;
    tempShoe1 = first;

    if (tempShoe1 == NULL){
        cout &lt;&lt; "List empty." &lt;&lt; endl;
        cout &lt;&lt; endl;
        system("PAUSE");
        MenuSportShoe();        
    }

    else{
        while(tempShoe1){
            cout &lt;&lt; "Sport Shoe Section." &lt;&lt; endl;
            cout &lt;&lt; "ID =&gt;&gt; " &lt;&lt; tempShoe1-&gt;ShoeID &lt;&lt; endl;
            cout &lt;&lt; "Brand =&gt;&gt; " &lt;&lt; tempShoe1-&gt;BrandShoe &lt;&lt; endl;
            cout &lt;&lt; "Type =&gt;&gt; " &lt;&lt; tempShoe1-&gt;TypeShoe &lt;&lt; endl;
            cout &lt;&lt; "Colour =&gt;&gt; " &lt;&lt; tempShoe1-&gt;ColourShoe &lt;&lt; endl;
            cout &lt;&lt; "Size =&gt;&gt; " &lt;&lt; tempShoe1-&gt;SizeShoe &lt;&lt; endl;
            cout &lt;&lt; "Price =&gt;&gt; " &lt;&lt; tempShoe1-&gt;PriceShoe &lt;&lt; endl;
            cout &lt;&lt; endl;
            tempShoe1 = tempShoe1-&gt;last;
        }
        system("PAUSE");
        MenuSportShoe();
    }
}

void HighHeel::DisplayHighHeel() {
    nodeHeel *tempHeel1;
    tempHeel1 = start;

    if (tempHeel1 == NULL){
        cout &lt;&lt; " List empty." &lt;&lt; endl;
        cout &lt;&lt; endl;
        system("PAUSE");
        MenuHighHeel();     
    }

    else{
        while(tempHeel1){
            cout &lt;&lt; "Heel Section." &lt;&lt; endl;
            cout &lt;&lt; "Heel Code =&gt;&gt; " &lt;&lt; tempHeel1-&gt;ProductCode &lt;&lt; endl;
            cout &lt;&lt; "Brand =&gt;&gt; " &lt;&lt; tempHeel1-&gt;BrandHeel &lt;&lt; endl;
            cout &lt;&lt; "Material =&gt;&gt; " &lt;&lt; tempHeel1-&gt;MaterialHeel &lt;&lt; endl;
            cout &lt;&lt; "Colour =&gt;&gt; " &lt;&lt; tempHeel1-&gt;ColourHeel &lt;&lt; endl;
            cout &lt;&lt; "Height (cm) =&gt;&gt; " &lt;&lt; tempHeel1-&gt;HeightHeel &lt;&lt; endl;
            cout &lt;&lt; "Price =&gt;&gt; " &lt;&lt; tempHeel1-&gt;PriceHeel &lt;&lt; endl;
            cout &lt;&lt; endl;
            tempHeel1 = tempHeel1-&gt;next;
        }
        system("PAUSE");
        MenuHighHeel();
    }
}

void SportShoe::DeleteSportShoe(){
    nodeSport *tempShoe1, *tempShoe2; 
    int DataShoe;

    cout &lt;&lt; "Sport Shoe Section." &lt;&lt; endl;
    cout &lt;&lt; "\nEnter the Shoes ID to be deleted: (eg. 123) "&lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; DataShoe;
    tempShoe2 = tempShoe1 = first;

    while((tempShoe1 != NULL) &amp;&amp; (DataShoe == tempShoe1-&gt; ShoeID))
    {
        tempShoe2 = tempShoe1;
        tempShoe1 = tempShoe1-&gt;last;
    }

    if(tempShoe1 == NULL)
    {
        cout &lt;&lt; "\nRecord not Found!!!" &lt;&lt; endl;
        system("PAUSE");
        MenuSportShoe();
    }

    if((tempShoe1 == first) &amp;&amp; (DataShoe == tempShoe1-&gt; ShoeID))
    {
        first = first-&gt;last;
        cout &lt;&lt; "\nData found " &lt;&lt; endl;
    }

    else{
        tempShoe2-&gt;last = tempShoe1-&gt;last;
        if(tempShoe1-&gt;last == NULL){
            tempShoe2 = tempShoe2;
        }
    cout &lt;&lt; "\nData deleted "&lt;&lt; endl;
    }

    delete(tempShoe1);
    cout &lt;&lt; endl;
    system("PAUSE");
    MenuSportShoe();
}

void HighHeel::DeleteHighHeel(){
    nodeHeel *tempHeel1, *tempHeel2;  
    int DataHeel;

    cout &lt;&lt; "Heel Section." &lt;&lt; endl;
    cout &lt;&lt; "\nEnter the Heel Code to be deleted: (eg. 123) "&lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; "; 
    cin &gt;&gt; DataHeel;
    tempHeel2 = tempHeel1 = start;

    while((tempHeel1 != NULL) &amp;&amp; (DataHeel == tempHeel1-&gt;ProductCode))
    {
        tempHeel2 = tempHeel1;
        tempHeel1 = tempHeel1-&gt;next;
    }

    if(tempHeel1 == NULL)
    {
        cout &lt;&lt; "\nRecord not Found!!!" &lt;&lt; endl;
        system("PAUSE");
        MenuHighHeel();
    }

    if(tempHeel1 == start)
    {
        start = start-&gt;next;
        cout &lt;&lt; "\nData deleted "&lt;&lt; endl;
    }

    else{
        tempHeel2-&gt;next = tempHeel1-&gt;next;
        if(tempHeel1-&gt;next == NULL){
            tempHeel2 = tempHeel2;
        }

    cout &lt;&lt; "\nData deleted "&lt;&lt; endl;
    }

    delete(tempHeel1);
    cout &lt;&lt; endl;
    system("PAUSE");
    MenuHighHeel();
}

void SportShoe::ExitSportShoe(){
    int sepatu;

    cout &lt;&lt; endl;
    cout &lt;&lt; "&gt;&gt; Please choose the option below &lt;&lt;"&lt;&lt;endl;
    cout &lt;&lt; ":: 1 :: Sport Shoe." &lt;&lt; endl;
    cout &lt;&lt; ":: 2 :: Ladies High Heel." &lt;&lt; endl;
    cout &lt;&lt; ":: 3 :: Exit" &lt;&lt; endl;
    cout &lt;&lt; "=&gt;&gt; ";
    cin &gt;&gt; sepatu;

    while(sepatu == 1){
        SportShoe listShoe;
        listShoe.MenuSportShoe();
    }

    while(sepatu == 2){
        HighHeel listShoe;
        listShoe.MenuHighHeel();
    }

    while(sepatu == 3){
        cout &lt;&lt; "&gt;&gt; Have a nice day. See you soon! &lt;&lt;"&lt;&lt; endl;
        exit(1);
    }
}

main() {

    cout &lt;&lt; "&gt;&gt; Hello! Welcome to MySepatu Online (Administrator Site) &lt;&lt;"; 
    cout &lt;&lt; endl;

    SportShoe::ExitSportShoe();

    return 0;
}
</code></pre>
