#include <iostream>
#include<string>

using namespace std;
long int NN;
int x=0;
class node *temp, *temp2 ,*start;
	class linked_list
{
		
		
		public:
			class node
			 { 
			 public:
				 char name[20];   
				 long int national_number;         
				 char residance[25];    
				 node *nxt;
				 
			 };
//--------------------------------->
			linked_list()
			{
				node *start;
				start=new node;
				cout<<"NAME            : Hussam Adel Abu Lubbad"<<endl;
				cout<<"nathiona number : 2007217345"<<endl;
				cout<<"residance       : jarash"<<endl;
			}
//--------------------------------->	
				void insert_at_end()
  {  
	  
	 node *temp, *temp2,*start; 
     temp = new node;

     cout << "Please enter the name of the person: ";
      cin >> temp->name;
     cout << "Please enter the  national number of the person : ";
      cin >> temp->national_number;
     cout << "Please enter the residance of the person : ";
      cin >> temp->residance;
     temp->nxt = NULL;

     
     if (start == NULL)
		   start = temp;
     else
       { 
		   temp2 = start;
		   while (temp2->nxt != NULL)
           {  
			   temp2 = temp2->nxt;
           }
         temp2->nxt = temp;
		 temp2->nxt=NULL;
	   }
  }
//--------------------------------->	
				void print_all_list()
  {  
	  
	  node *temp ,*start;
      temp = start;
			if (temp == NULL)
				 cout << "The list is empty" << endl;
			else
			{ 
		   
		   while (temp != NULL)
				{  
				  cout << "Name : " << temp->name << " ";
				  cout << "national number : " << temp->national_number << " ";
				  cout << "residance : " << temp->residance;
   				  temp = temp->nxt;

				}
			cout << "E.O.L" << endl;
			}
  }

//--------------------------------->		
				void print_irbid()
  { 
	  node *temp,*start;
      temp = start;
      if (temp == NULL)
            cout << "The list is empty!" << endl;
      else
	  { 
		 
		 while (temp != NULL)
	    {  
		   if(temp->residance == "irbid")
	        {
              cout << "Name : " << temp->name << " ";
              cout << "national number : " << temp->national_number << " ";
			  cout << "residance : " << temp->residance;
		      temp=temp->nxt;
	        }
		   else
		   
	      temp = temp->nxt;
	    }
	 cout << "E.O.L" << endl;
       }
  }
//--------------------------------->
				void delete_the_first()
  { 
	   node *temp ,*start;
       temp = start;
       start = start->nxt;
       delete temp;
  }
//--------------------------------->
				void delete_the_last_person()
{		
				   node *temp, *temp2,*start;
    if (start == NULL)
			       cout<< "it is empty"<<endl;
    else
				  { 
					temp = start;
          
	if (temp->nxt == NULL)
             { 
				 delete temp;
                 start = NULL;
             }
    else
             { 
				 while (temp->nxt != NULL)
                { 
					temp2 = temp;
                    temp = temp->nxt;
                }
					 delete temp;
					 temp2->nxt = NULL;
             }
        }
}
//--------------------------------->
			void delete_this(long int NN)
			{
				   node *temp, *temp2,*start;
				   cout<<"please enter the national # of the person to delete it form the list"<<endl;
				    cin>>NN;
			  if (start == NULL)
				     cout<< "it is empty"<<endl;
			 else
					temp = start;
             while (temp->nxt != NULL)
				    { 
						while(temp->national_number != NN)
					    {
							temp2 = temp;
						    temp = temp->nxt;
				    	}
						temp2->nxt =temp->nxt;
						 delete temp;
					 }
			 cout<<"there is no national number match the one you have entered"<<endl;
					 }

//--------------------------------->
			void cont_ali()
					{
			int cont=0;
			node *temp ,*start;
			temp = start;
			if (temp == NULL)
			  cout << "The list is empty!" << endl;
			else
				 { 
					 while (temp != NULL)
		    			 {  
						  if(temp->name == "ali")
			     		 {
			 cont++;
             cout << "Name : " << temp->name << " ";
             cout << "national number : " << temp->national_number << " ";
	         cout << "residance : " << temp->residance;
			 temp=temp->nxt;

				}
					 else
					   temp = temp->nxt;
				}
     cout << "E.O.L" << endl;
	 cout<<"the # of persons with name Ali in this list is --->"<<cont<<endl; 

			}
			}
//--------------------------------->
             void insert_at_the_first()
			 {
				node *temp, *temp2 ,*start ; 
				temp = new node;

     cout << "Please enter the name of the person: ";
      cin >> temp->name;
     cout << "Please enter the  national number of the person : ";
      cin >> temp->national_number;
     cout << "Please enter the residance of the person : ";
      cin >> temp->residance;
     temp->nxt = NULL;

     
     if (start == NULL)
		   start = temp;
     else
       { 
		 temp2 = start;
		 start=temp;
	   }

}



//--------------------------------->
			};


void main()
  { 
	  linked_list::node *start;
	  start = NULL;
linked_list in;
     do
	{
	 void print_all_list();
	  cout << endl;
	  cout << "Please select an option : "<<endl;
	  cout << "0. Exit the program."<<endl;
	  cout << "1. Add a person to end of the list."<<endl;
	  cout << "2. print all list."<<endl;
	  cout << "3. print the persons who leave in irbid."<<endl;
	  cout << "4. delete the first person in the list."<<endl;
      cout << "5. delete the last person on the list."<<endl;
	  cout << "6. cont how many persons in the list there name is ali ."<<endl;
	  cout << "7. delete by the national number."<<endl;
	  cout << "8. insert at the first of the list. "<<endl;
      
	  cin >> x;

	  switch (x)
	    {
	      case 1 : in.insert_at_end(); break;
	      case 2 : in.print_all_list(); break;
	      case 3 : in.print_irbid(); break;
	      case 4 : in.delete_the_first(); break;
          case 5 : in.delete_the_last_person();break;
		  case 6 : in.cont_ali(); break;
		  case 7 : in.delete_this(NN); break;
		  case 8 : in.insert_at_the_first();
	    }
	}
     while (x != 0);
  }

Recommended Answers

All 4 Replies

Compare your post to the following statement: My car only makes noise when it runs. Please help me fix it.

It's a very broad statement/request, isn't it? Please try to narrow things down. Start commenting out functions and funciton calls one by one---starting with the least important, and recompile/run the program until you can narrow down the location of the problem. Then repost asking something like--- "There's a run time error in my AddNode function. Can someone help me fix it?" If you get a specific error message post that too, with the relevant code lines/functions. Generally speaking, if you wait for someone to download, compile, run, and debug your program you will have a longer wait for an appropriate answer in addition to loosing the opportunity to learn how to debug your own code.

Also, pay some attention to use of code tags when posting code. This will maintain the indentation protocols you use and make it easier for responders to read your code.

commented: Well put +17

Compare your post to the following statement: My car only makes noise when it runs. Please help me fix it.

Indeed, moreso the equivalent of parking one's car diagonally across the repair bays at one's local service station and leaving it overnight.

(*the usual apologies for the bump but I had to get that one off my chest)

ok Lerner but u knw its a exams time i my university so i thought ....

any way this code is my data structure mid lab exam i took it on last starday 26/12/2009
i solve it like that and i took it with me and i didn't knw what is wrong with it ... :))

this for the advice i will try to do it :)) my self
thx for all

What compiler did you use? I compiled it with vc++ 2008 Express and got a lot of warnings about using uninitialized variables. Pay close attention to your compiler's warnings because they are often actual errors.

[edit]I compiled it with Code::Blocks (with MinGW) and it does not produce the warnings about uninitialized variables. Even -Wall flag does not produce the warnings.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.