الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

data structure

مغلق
بدأه leen_2004 في 20 نوفمبر 2004 · 1 رد · 425 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

كيف اعمل function

QueueSize for linked queue by using loop move pointer variable from node to node??????

how?/

also function TraverseQueue

#2

السلام عليكم

اختي اين

لو بحثتي كان لقيت مواضيع كثيره تفيدك

هذا ماتبحثين عنه وإن شاء الله يفيدك

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
//---------------------------------
struct Node
{
 char	name[20];    //define the name and ssi of the struct
 int	ssi;
 Node* next;
};
//-------------------------------------
class Queue
{
private:
	Node* front;
	Node* back;

public:
	Queue();
	void add();
	void remove();
	void display();
	void first();
	void last();

};
//-------------------------
void menu();
//--------fun construct-------------------

Queue::Queue()
{
	front=NULL;

	back=front;
}
//------------fun add------------------
void Queue::add()
{
	Node* temp;   
	temp=new Node;
	temp->next=NULL;
	cout<<"\n enter socal security number add:";    //read the ssi of the node top
               cin>>temp->ssi;
               cout<<"\n enter person to add:";     //read the name of the node top
            cin>>temp->name;
	if((front==NULL) || (back==NULL))              //no node or  one node
	{
  front=temp;
     back=temp;
    }
	else                                           //  node more  one
	{
	back->next=temp;
	back=temp;
	}
}
//--------------fun remove---------------------
void Queue::remove()
{
	Node* curn;
	curn=front;
	if(front==NULL)                  //check  is empty
	cout<<"\n the stack is empty";
	else
	cout<<'\n'<<front->ssi<<"\t\t\t"<<front->name;   //print the name and ssi  remove

	front=front->next;
	if(front==NULL)                          //no  node  

  back=NULL;
	delete curn;
}

//----------------fun display------------------------

void Queue::display()
{
	Node* curn;
	curn=front;
	if(front==NULL)
  cout<<"\nthe stack is empty";
	else
  while(curn != NULL)
  {
 	 cout<<'\n'<<curn->ssi<<"\t\t\t"<<curn->name;
 	 curn=curn->next;
  }
}
//-------------------fun first----------------------------------
void Queue::first()
{
   cout<<"\n The first socal security number"<<"\t person name";
   cout<<"\n"<<front->ssi<<"\t\t\t\t"<<front->name;
}
//----------------------fun last---------------------------------
void Queue::last()
{
	cout<<"\n The Last socal security number"<<"\t person name";
   cout<<"\n"<<back->ssi<<"\t\t\t\t"<<back->name;

}
//-------------------menu-------------------------

void menu()
{
 cout<<"\nmenu";
 cout<<"\n (A)dd";
 cout<<"\n (R)emove";
 cout<<"\n (F)irst";
 cout<<"\n (L)ast";
 cout<<"\n (D)isplay";
 cout<<"\n (Q)uit";
}
//---------------------------------------------------------

void main()
{
  Queue x;
  char choes;
  menu();
  do
  {

   cout<<"\npleas choes from menu:";
   cin>>choes;
   switch(choes)
   {
      case 'a':
      case 'A':
               x.add();                                    //call the add fun
            cout<<"\n***************************";
               break;
      case 'r':
      case 'R':cout<<"\n Remove socal security number"<<"\tRemove person name";
         
            x.remove();                                 //call the remove fun
         cout<<"\n***************************";
               break;
       case 'f':
       case 'F':x.first();                                 //call the first fun
                break;
       case 'l':   
       case 'L':x.last();                               //call the last fun
                cout<<"\n******************************";
                break;
       case 'd':
       case 'D':cout<<"\nsocal security number"<<"\t person name";
             x.display();                                    //call the display fun     
          cout<<"\n******************************";
                break;
       case 'q':
       case 'Q':cout<<"\n \t  GOD BAY \n"<<"\t \n";
             exit(0);
                break;
   }

  }while(1);
  

  getche();
}

هذا الموضوع مغلق.

مواضيع مشابهة