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

Data Structure With C++

بدأه كمبيوتر في 9 مارس 2008 · 2 رد · 905 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم..

أتمنى انكم تساعدوني لمعرفة الخطأ في هذا الكود...

الكود مكتوب بC++....و طبقته على برنامج eazy eclipse...

و هذا الكود..

#ifndef List_H_
#define List_H_
#include<iostream>
#include<string>
using namespace std;

//node declaration
template <class Type>
struct Node
{
	Type data;
	Node *link;
};
//book declaration
struct Book
{
	string Name;
	string Publisher;
	string Title;
};
//List declaration
template <class Type,class  KeyType>
class List
{
	private:
	Node<Type> *Head;
	Node<Type>  *pos;
	Node<Type>   *rear;
	int count;
	//function declaration
	bool insert(Node<Type> *Ppre,Type dataIn);
	void Delete (Node<Type> *Ppre,Node<Type>* ploc,Type *dataout);
	bool saerch (Node<Type> **Ppre,Node<Type> **ploc,KeyType K1,KeyType K2);

	public:
	List();
	~List();
	int AddNode(Type dataIn);
	bool removenode (KeyType K1,KeyType K2,Type *dataout);
};
#include "List.tem"
#endif
__________________________
#include<iostream>
#include<string>
using namespace std;
#include"List.h"

//.....................................................
template<class Type,class  KeyType>
List<Type,KeyType>::List()
{
	Head=NULL;
	pos=NULL;
	rear=NULL;
	count=0;
}
//............................................................
template<class Type,class  KeyType>
List<Type,KeyType>::~List()
{
	Node<Type> *deletptr;
	if(Head)
	{
		while (count>0)
		{
			deletptr=Head;
			Head=Head->link;
			count--;
			delete deletptr;
		}
	}
}
//................................................................................
....
 template<class Type,class  KeyType>
bool  List<Type,KeyType>::saerch (Node<Type> **Ppre,Node<Type> **ploc,KeyType K1,KeyType K2)
{
	bool Found;
	*Ppre=NULL;
	*ploc=Head;
	if(count==0)
	return Found=false;
	if(K1> rear->data.Publisher)
	{
 	*Ppre=rear;
	*ploc=NULL;
	return false;
	 }
	else
	while(ploc !=NULL && K1>(*ploc)->data.Publisher)
	{
	*Ppre=*ploc;
	*ploc=(*ploc)->link;
	}
	if(K1==(*ploc)->data.Publisher)
	{
	while(K2>(*Ppre)->data.Title)
	{
	*Ppre=*ploc;
	*ploc=(*ploc)->link;
	}
	if(*ploc==NULL)
	Found=false;
	else
		 {
		 if(K2==(*ploc)->data.Title)
		 Found=true;
		 else
		 Found=false;
		 }
		 //return Found=false;
	return Found=false;
	}
	return Found;

}

//....................................................................
template<class Type,class  KeyType>
int List<Type,KeyType>::AddNode(Type dataIn)
{
	bool found;
	bool success;
	Node<Type> *Ppre;
	Node<Type> *ploc;
	 found=search(&Ppre,&ploc,dataIn.Publisher,dataIn.Title);
	if(found)
	return(+1);
	success=insert(Ppre,dataIn);
	if(!success)
	return(-1);
	return (0);
}
//..........................................................................
template<class Type,class  KeyType>
bool List<Type,KeyType>::removenode(KeyType K1,KeyType K2,Type *Pdataout)
{
bool found;
Node<Type> *Ppre,*ploc;
found=search(&Ppre,ploc,K1,K2);
if(found)
Delet(Ppre,ploc,Pdataout);
return found;

}
//.....................................................................
template<class Type,class  KeyType>
bool List<Type,KeyType>::insert(Node<Type> *Ppre,Type dataIn)
{
	Node<Type> *pnew;
	if(! (pnew=new Node<Type> ))
	return false;
	pnew->data=dataIn;
	pnew->link=NULL;
	if(Ppre==NULL)
	{
		pnew->link=Head;
		Head=pnew;
	}
	else
	{
		pnew->link=Ppre->link;
		Ppre->link=pnew;
	}
	if(pnew->link==NULL)
	rear=pnew;
	count++;
	return true;

}
//...................................................................
template<class Type,class  KeyType>
void  List<Type,KeyType>::Delete(Node<Type> *Ppre,Node<Type> *ploc,Type  *Pdataout)
{
*Pdataout=ploc->data;
if(Ppre==NULL)
Head=ploc->link;
else
Ppre->link=ploc->link;
if(ploc->link==NULL)
rear=Ppre;
count--;
delete ploc;
return;

}
//......................................................................
___________________________________
#include<iostream>
#include<string>
using namespace std;
#include"List.h"

int main()
{
List<Book,string> List1;
Node<Book> Node1;
Book Book1;

int x;
cout<<"Enter  x=1 to write the information and x=-1 to exit\n ";
cin>>x;
while(x!=-1)
{

	cin>>Book1.Name;
	cin>>Book1.Publisher;
	cin>>Book1.Title;
	cout<<"enter x";
	cin>>x;
}
List1.AddNode(Book1);



	return 0;
}
_____________________

ممكن تساعدوني..كيف أخلي الكود يظهر بشكل سليم..

و جزاكم الله خيير..

طبعا الكود مستخدمة فيه LinkedList

تم تعديل هذه المشاركة بواسطة GamingMasteR في 9 مارس 2008 في 22:53 — السبب: code

#2
اقتباس
ممكن تساعدوني..كيف أخلي الكود يظهر بشكل سليم..

ما هو الشكل السليم؟

و ممكن كمان يا أختى تعملى نسخة من الكود فى فايل واحد علشان أقدر أجربه و أشوف الخطأ فين؟

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