Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,291 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 933 people online right now. Registration is fast and FREE... Join Now!




need help for my linked list... =P

 
Reply to this topicStart new topic

need help for my linked list... =P, pls check for any problems...thx...^^

joeypepe
31 Jan, 2008 - 11:25 PM
Post #1

New D.I.C Head
*

Joined: 31 Jan, 2008
Posts: 4

CODE

#include <iostream>
#include <cstdlib>
using namespace std;


class link
{
public:
    int num;
    link *ptr;
    void add();
    void del();
    void ins();
    void disp();
    void end();
};

link *start = NULL;
link *current;
int choice1;
int dispchoice;
int choice;

int main()
{
    link list;
    start = NULL;

    cout<<"\t\t##MENU##"<<endl;
    cout<<"\tPress 1 to Continue"<<endl;
    cout<<"\tPress 0 to Exit"<<endl;
    cin>>choice;

    system ("cls");

    switch(choice)
    {
    case 1: do
            {
                cout<<"\t\t##MENU##"<<endl;
                cout<<"[1]Add Element"<<endl;
                cout<<"[2]Insert Element"<<endl;
                cout<<"[3]Delete Element"<<endl;
                cout<<"[4]Display List"<<endl;
                cout<<"[0]Exit"<<endl;
                cout<<"Enter Your Choice: ";
                cin>>choice1;

                system ("cls");

                switch (choice1)
                {
                case 1: system ("cls");
                    link.add();
                    break;
                case 2: system ("cls");
                    link.ins();
                    break;
                case 3: system ("cls");
                    link.del();
                    break;
                case 4: system ("cls");
                    link.disp();
                    break;
                case 0: system ("cls");
                    link.end();
                    break;
                }
            }while (choice > 4);
            system ("cls");
            break;
    case 0: system ("cls");
            link.end();
            break;
    }

return 0;
}
void link::add()
{
    link *temp1, *temp2;

    temp1 = new link;

    cout<<"Enter The Number to be Added on the List: ";
    cin>>temp1->num;

    if (start == NULL)
    {
        start = temp1;
        current = start;
    }
    else
    {
        temp2 = start;
        while (temp2->ptr != NULL)
        {
            temp2 = temp2->ptr;
        }
        temp2->ptr = temp1;
    }
    system ("cls");
    
    return;
}
void link::disp()
{
    link *temp;
    temp = start;
    
    if (temp == NULL)
    {
        cout<<"Empty List..."<<endl;
        system ("cls");
    }
    else
    {
        while (temp != NULL)
        {
            cout<<"Number: "<<temp->num<<endl;
            if (temp == current)
                temp = temp->ptr;
        }
    }
    
    return;
}
void link::end()
{
    cout<<"Thank You..."<<endl;
    return;
}
void link::del()
{
    link *temp1, *temp2;

    if (start == NULL)
        cout<<"Empty List..."<<endl;
    else
    {
        temp1 = start;
        if (temp1->ptr == NULL)
        {
            delete temp1;
            start = NULL;
        }
        else
        {
            while (temp1->ptr != NULL)
            {
                temp2 = temp1;
                temp1 = temp1->ptr;
            }
            delete temp1;
            temp2->ptr = NULL;
        }
    }

    return;
}




can u pls check for any problems....it has some sort of error...^^

thanks a bunch...^^

User is offlineProfile CardPM
+Quote Post


jjhaag
RE: Need Help For My Linked List... =P
1 Feb, 2008 - 12:12 AM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 7 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
Are you talking compiler errors? Runtime errors? Or is it not producing the expected results?

Please describe your problem in greater detail (including posting of compiler errors) so that it's easier for us to help you.
User is offlineProfile CardPM
+Quote Post

joeypepe
RE: Need Help For My Linked List... =P
1 Feb, 2008 - 12:16 AM
Post #3

New D.I.C Head
*

Joined: 31 Jan, 2008
Posts: 4

QUOTE(jjhaag @ 1 Feb, 2008 - 01:12 AM) *

Are you talking compiler errors? Runtime errors? Or is it not producing the expected results?

Please describe your problem in greater detail (including posting of compiler errors) so that it's easier for us to help you.


ummm...syntax error...i think...i tried to change the class' name but once i change it, there was syntax errors everywhere!!! =p

before i tried to change the class' name, there was this fatal error thing...(unresolved externals)....pls help... cool.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 04:00PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month