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

شنو الايرور في البرنامج؟؟

مغلق
بدأه ABOMAHDI في 25 مايو 2005 · 4 رد · 484 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
#include<iostream.h>
#include<assert.h>

typedef struct node*ptrtype;
typedef itemtype itemtype;
struct node{
itemtype item;
ptrtype next;
};

class stack{
private:
ptrtype top;
puplic:
stack();
stack(const stack&s);
~stack();
int isempty();
int isfull(ptrtype p);
int push(itemtype newitem);
int pop();
int gettop(itemtype &item);
const ptrtype gettopptr();
};

stack::stack(){top=NULL;}
stack::stack(const stack &s){
if(s.gettopptr()==NULL)
top=NULL;
else{
top=new node;
assert(top!=NULL);
top->item = s.gettopptr()->item;
ptrtype newlist=top;
for(const node* curlist=s.gettopptr()->next;curlist 
!=NULL;curlist->next)
{
newlist->next=new node;
assert(newlist->next !=NULL);
newlist=newlist->next;
newlist->item = curlist->item;
}
newlist->next=NULL;
}
}
stack::~stack(){
int more = pop();
while(more) more = pop();
}
int stack::isempty(){
return(top==NULL);
}
int stack::isfull(temp)){
return(0);
} else{
temp->item = newitem;
temp->next = top;
top=temp;
return(1);
}
}
int stack::pop(){
if(isempty()){
return(0);
}
else{
ptrtype temp =top; top = top->next;
delete temp;
return(1);
}
}
int stack::gettop(itemtype &item){
if (isempty()){
return(0);
}
else{
itemm = top->item; return(1);
}
}
const ptrtype stack::gettopptr()
{return(top);};

void main(){
stack s;
int k;
int b;
while (1)
{
assert();
cout<<" Please select one of the following \n";
cout<<" 1- isempty\n";
cout<<" 2- isfull\n";
cout<<" 3- push\n";
cout<<" 4- pop\n";
cout<<" 5- gettop\n";
cout<<" 6- exit\n\n"<<endl;
cin>>k
switch(k)
  {
	case 1:{
     s.isempty();
     break;
     }
	case 2:{
     cin>>b
     s.isfull(B);
     break;
     }
	case 3:{
     cin>>b;
     s.push(B);
     break;
     }
	case 4:{
    s.pop();
    break;}
	case 5:{
     cin>>b
     s.gettop(B);
     break;}

     }

	case 6: exit(1);
	default :cout<<" wrong selection";
}}


}

تم تعديل هذه المشاركة بواسطة احمد غريب في 25 مايو 2005 في 20:41

#2

ماهو الerror الذي يظهر لك؟

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#3

السلام عليكم

typedef struct node*ptrtype;
typedef itemtype itemtype;

لم اقراء البرنامج كله ولكن هناك مشكله كبيره فى بداية البرنامج, المعرف node تقوم بتغيره إلى مؤشر وكما نعلم فإن المؤشر هو عنوان وحجمه كحجم int فى حين ان node هى فى الواقع من نوع struct>

السطر الثانى لا يقوم بعمل شيئ هو فقط يغير إسم itemtype ويسميه itemtype يعنى لا يفعل شيئ على الاطلاق.

على كل حال المشكله التى فى السطر الاول لابد ان تحل قبل الاطلاع على باقى البرنامج لانها تشكل عقبه فى فهم باقى البرنامج.

والسلام عليكم

لا إله إلا الله محمد رسول الله

busbar : يجب ان تدرك انه هناك حد ادنى للمعرفة المطلوبة قبل البدء في عمل أي شئ.

#4

الكود ملخبط على الاخر

ماذا تعني بهذا؟؟؟؟؟؟

int stack::isfull(ptrtype temp){
return(0);
} else{
temp->item = newitem;
temp->next = top;
top=temp;
return(1);
}
}

فليس له معنى

و هذا ايضا

typedef itemtype itemtype;

و ايضا كلمة public مكتوبة puplic:

و هذا الconstructor ايضا لماذا تستخدم const

stack::stack(const stack &s){
if(s.gettopptr()==NULL)
top=NULL;
else{
top=new node;
assert(top!=NULL);
top->item = s.gettopptr()->item;
ptrtype newlist=top;
for(const node* curlist=s.gettopptr()->next;curlist
!=NULL;curlist->next)
{
newlist->next=new node;
assert(newlist->next !=NULL);
newlist=newlist->next;
newlist->item = curlist->item;
}
newlist->next=NULL;
}
}

انت تقريبا جايب code بتاع linkedlist على code بتاع stack و ملخبطهم على بعض من غير ماتعمل compile و لا مرة عشان تتاكد اذا كان فيه اخطاء و الا لآ

الكود ده محتاج اعادة كتابة

انا خليت الكود مايطلعش compile errors بس المشكلة ان الكود مش بيشتغل لان في مناطق غير مفهومة بالمرة

#include<iostream.h>
#include<assert.h>
#include <stdlib.h>
typedef struct node* ptrtype;
typedef int itemtype;
struct node{
itemtype item;
ptrtype next;
};

class stack{
private:
ptrtype top;
public:
stack();
stack(stack&s);
~stack();
int isempty();
int isfull(ptrtype p);
int push(itemtype newitem);
int pop();
int gettop(itemtype &item);
const ptrtype gettopptr();
};

stack::stack(){top=NULL;}
stack::stack( stack &s){
if(s.gettopptr()==NULL)
top=NULL;
else{
top=new node;
assert(top!=NULL);
top->item = s.gettopptr()->item;
ptrtype newlist=top;
for(const node* curlist=s.gettopptr()->next;curlist
!=NULL;curlist->next)
{
newlist->next=new node;
assert(newlist->next !=NULL);
newlist=newlist->next;
newlist->item = curlist->item;
}
newlist->next=NULL;
}
}
stack::~stack(){
int more = pop();
while(more) more = pop();
}
int stack::isempty(){
return(top==NULL);
}
int stack::isfull(ptrtype temp){
return(0);
}

int stack::pop(){
if(isempty()){
return(0);
}
else{
ptrtype temp =top; top = top->next;
delete temp;
return(1);
}
}
int stack::gettop(itemtype &item){
if (isempty()){
return(0);
}
else{
item = top->item; return(1);
}
}
const ptrtype stack::gettopptr()
{return(top);};

void main(){
stack s;

int k;
int b;
while (1)
{

cout<<" Please select one of the following \n";
cout<<" 1- isempty\n";
cout<<" 2- isfull\n";
cout<<" 3- push\n";
cout<<" 4- pop\n";
cout<<" 5- gettop\n";
cout<<" 6- exit\n\n"<<endl;
cin>>k;
switch(k)
 {
case 1:{
    s.isempty();
    break;
    }
case 2:{
    cin>>b;

    break;
    }
case 3:{
    cin>>b;
    s.push(b);
    break;
    }
case 4:{
   s.pop();
   break;}
case 5:
    cin>>b;
    break;


case 6: 
	exit(1);
default :cout<<" wrong selection";
}}


}

حاول ان تعيد كتابته

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#5

السلام عليكم

تخيل انا فهمت السطر دا

typedef struct node*ptrtype;

على إنه كدا

typedef struct node *ptrtype;

ودا طبعاًُ حيخلى الكمبايلر يغير كل كلمة node ويحط مكانها ptrtypr* ,ويبوز الدنيا خالص, الان اتضحت الصوره وكما قال الباشمهندس isFull مثلاُ عليه ان يتحقق من حجم المكدس فقط, ولكنه فى الكود المرفق يضيف عنصر جديد وهذه ليست وظيفه isFull.

بالفعل الكود كله يحتاج إلى كتابته من جديد.

والسلام عليكم

لا إله إلا الله محمد رسول الله

busbar : يجب ان تدرك انه هناك حد ادنى للمعرفة المطلوبة قبل البدء في عمل أي شئ.

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

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…