Feb 21, 2012 at 3:13pm UTC
guys my display and delete has an error sorry if i`m too dumb for this one..can somebody help me please! Godbless and thank you in advance to those will try to help...:]
#include<iostream>
using namespace std;
struct node
{
int data;
node *link;
};
int main()
{
char loop = 'Y';
while(loop == 'Y' || loop == 'y')
{
int menu;
int opt;
int num;
int del;
struct node *first;
cout<<"___________________________________________________________"<<endl<<endl;
cout<<" LINKED LIST"<<endl;
cout<<"___________________________________________________________"<<endl;
cout<<"\n\n\t\t-=M E N U=-"<<endl;
cout<<"\n\t[1] Insert Node";
cout<<"\n\t[2] Delete Node";
cout<<"\n\t[3] Display Node";
cout<<"\n\t[4] Exit";
cout<<"\n\nEnter your choice: ";
cin>>menu;
switch(menu)
{
case 1:
{
cout<<"\n\t\tYou choose insert node."<<endl<<endl;
cout<<"Enter a node: ";
cin>>num;
node* newnode;
newnode= new node;
newnode->data= num;
(newnode->link) = NULL;
first = newnode;
cout<<"A new node was added on your list."<<endl;
break;
}
case 2:
{
cout<<"\n\t\tYou choose Delete node."<<endl<<endl;
node* temp;
if(first == NULL)
{
cout<<"\nYour list is empty";
}
if(first->link == NULL)
{
temp = first;
first = NULL;
cout<<"\nDeleted node: "<<temp->data;
free(temp);
}
else
{
temp = first;
first = first->link;
cout<<"\nDeleted node: "<<temp->data;
free(temp);
}
break;
}
case 3:
{
cout<<"\n\t\tYou choose display node."<<endl<<endl;
node* temp;
if(first == NULL)
{
cout<<"\n Your list is empty "<<endl;
}
temp = first;
cout<<"Here are your node/s: "<<endl;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp = first;
}
break;
}
case 4:
{
exit(0);
}
default:cout<<"Invalid Input";
}
}
cout<<"Do you want to continue?";
cin>> loop;
system("pause");
}