#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
using namespace std;
struct node
{
    string data;
    node* next;
    node* bel;
};
class tree
{
public:
    node* head;
    tree()
    {
        head = NULL;
    }
    void insertmov(string mov)
    {
        node* n = new node;
        n->next = NULL;
        n->bel = NULL;
        n->data = mov;
        if (head == NULL)
        {
            head = n;
        }
        else
        {       
            node* temp = new node;
            
            temp = head;
            while (temp->next != NULL)
            {
                    
                temp = temp->next;
            }
            temp->next = n;
        }
    }
    void insert_actor(string mov, string act)
    {
        node* temp = new node;
        node* n = new node;
        n->next = NULL;
        n->bel = NULL;
        n->data = act;
        for (temp = head; temp != NULL; temp = temp->next)
        {
            if (temp->data == mov)
            {
                for (temp = temp; temp != NULL; temp = temp->bel)
                {
                    if (temp->bel == NULL)
                    {
                        temp->bel = n;
                        break;
                    }
                }
                break;
            }
        }
    }
    void printm(node *n)
    {
        node* temp = new node;
        temp = n;
        if (temp == NULL)
        {
            cout << "\nNo Movie ";
        }
        else if (temp->next == NULL)
        {
            cout  << temp->data<<endl;
        }
        else
        {
            cout  << temp->data<<endl;
            printm(temp->next);
        }
    }
    void print_actor(string mov)
    {
        node* temp = new node;
        temp = head;
        if (temp == NULL)
        {
            cout << "\nNo Movie ";
        }
        else
        {
            while (temp != NULL)
            {
                if (temp->data == mov)
                {
                    while (temp != NULL)
                    {
                        temp = temp->bel;
                        cout << "\n" << temp->data;
                        if (temp->bel == NULL)
                            break;
                    }
                }
                else
                {
                    temp = temp->next;
                }
                if (temp->next == NULL)
                    break;
            }
        }
    }
};
int main()
{
    tree t;
    ifstream input;
    int ch;
    input.open("C:\\Users\\Zubair\\mov.txt");
    string sec, fir;
    while (!input.eof())
    {
        getline(input, fir);
        if (fir == "#")
        {
            getline(input, sec);
            t.insertmov(sec);
        }
        else
        {
            t.insert_actor(sec, fir);
        }
    }
    input.close();
    do
    {
        cout << "\n\nMenu \n";
        cout << "1.Show the list of movies \n";
        cout << "2.Search\n";
        cout << "3.Exit\n";
        cout << "Enter Your Choice \n";
        cin >> ch;
        switch (ch)
        {
            case 1:
            {
                system("CLS");
                cout << "\n List of Movies \n";
                t.printm(t.head);
                break;
            }
            case 2:
            {
                string st;
                char inp[50];
                system("CLS");
                cin.ignore();
                cout << "\n\n Enter The Name Of Moive \n";
                getline(cin, st);
                t.print_actor(st);
                break;
            }
        }
    } while (ch != 3);
}
The task is to build this database using a Linked List data structure.
Tasks:
- String (to store the name of the movie or an actor)
- Pointer to the next node in the linked list.
- Pointer to the node below the current node.
Problem :
I am unable to search the first and last movie, and not getting answers.
PS: I am a noob but want to learn. Ignore my silly mistakes and inform me about it so that I can improve them.
File contains data in a way that the first line represents a movie and then some actors that worked in the movie. Then, before the next movie there is # so it can be detected.


 
    