محمد قاسم المولجي نجم جديد
عدد الرسائل : 7 العمر : 37 التخصص : انظمة معلومات حاسوبية تاريخ التسجيل : 29/07/2008
| موضوع: هنا برامج الداتاستركشر(list - stack - queue ) كاملة الإثنين ديسمبر 15, 2008 7:09 am | |
| السلام عليكم ورحمة الله اهدي طلاب الداتا ستركشر هذه المجموعة من البرامج بمناسبة عيد الاضحى وهي برامج كاملة unsorted list #include enum relation{less,equal,greater}; const int max=10; class itemtype { private: int value; public: relation compare(itemtype other); void initialized(int num); void print(); }; relation itemtype::compare(itemtype other) { if(valuereturn less; else if(value>other.value) return greater; else return equal; } void itemtype::initialized(int num) { value=num; } void itemtype::print() { cout<} class unsortedtype { private: int length; itemtype lt[max]; public: unsortedtype(){length=0;} void insertitem(itemtype item); bool empty(){return length==0;} bool full(){return length==max;} void deleteitem(itemtype item); void search(itemtype item,bool&found); void print(); void reset(); }; void unsortedtype::insertitem(itemtype item) { lt[length]=item; length++; }
void unsortedtype::deleteitem(itemtype item) { int location=0; while(item.compare(lt[location])!=equal) location++; lt[location]=lt[length-1]; length--; }
void unsortedtype::search(itemtype item,bool&found) {int location=0; bool moresearch=(locationfound=false; while(moresearch&&!found) {switch (item.compare(lt[location])) {case less: case greater: location++; moresearch=(locationbreak; case equal: found=true; break; } } }
void unsortedtype::print() { for(int z=0;zlt[z].print(); cout<}
void unsortedtype::reset() { length=0; } void main() { bool found; unsortedtype a; itemtype z; int x,y; do{ cout<<"1)insert\t2)delete\t3)search\t4)print \t5)reset\nchoose\n"; cin>>x; switch(x) { case (1):found=false; cout<<"insert the item that you want to insert\n"; cin>>y; z.initialized(y); a.search(z,found); if(found) cout<<"the item is inserted before\n"; else { if(!a.full()) {a.insertitem(z); cout<<"the item is inserted\n"; } else cout<<"it's full\n"; } break; case (2):if(!a.empty()) { found=false; cout<<"insert the item that you want to delete\n"; cin>>y; z.initialized(y); a.search(z,found); if(found) {a.deleteitem(z); cout<<"the item is deleted\n"; } else cout<<"the item isn't found \n"; } else cout<<"it's empty\n"; break; case (3):found=false; cout<<"insert the item that you want to search\n"; cin>>y; z.initialized(y); a.search(z,found); if(found) cout<<"the item is found\n"; else cout<<"the item is not found\n"; break; case (4):if(!a.empty()) a.print(); else cout<<"no item to print\n"; break; case (5):a.reset(); cout<<"ok the list reset is done\n"; break; } } while(x>0 && x<6); }
sorted list #include enum relation{less,greater,equal}; const int max=10; class itemtype { private: int value; public: relation compared(itemtype item); void iniailized(int num); void print(); }; relation itemtype::compared(itemtype item) { if(value>item.value) return greater; else if(valuereturn less; else return equal; } void itemtype::iniailized(int num) { value=num; } void itemtype::print() { cout<} class sorted { private: int length; itemtype info[max]; public: sorted():length(0){} void insert(itemtype item); bool empty(){return length==0;} bool full(){return length==max;} void deleted(itemtype item); void search(itemtype item,bool&found); void print(); void reset(); }; void sorted::insert(itemtype item) { int location=0; bool more=(locationwhile(more) { switch(item.compared(info[location])) { case less: more=false; break; case greater: location++; more=(location break; } } for(int index=length;index>location;index--) info[index]=info[index-1]; info[location]=item; length++; } void sorted::deleted(itemtype item) { int location=0; while(item.compared(info[location])!=equal) location++; for(int index=location+1;indexinfo[index-1]=info[index]; length--; } void sorted::search(itemtype item,bool &found) {int midpoint; int first=0; int last=length-1; found=false; bool more=(first<=last); while(more&&!found) {midpoint=(last+first)/2; switch(item.compared(info[midpoint])) { case less: last=midpoint-1; more=(first<=last); break; case greater: first=midpoint+1; more=(first<=last); break; case equal: found=true; break; } } } void sorted::print() { for(int z=0;zinfo[z].print(); cout<}
void sorted::reset() { length=0; } void main() { bool found; sorted list; itemtype h; int x,y; do {cout<<"Mohammed Qassim Almolijy\n1)insert\t2)delete\t3)search\t4)print \t5)reset\ninsert your choice\n"; cin>>x; switch(x) { case (1):found=false; cout<<"insert the item\n"; cin>>y; h.iniailized(y); list.search(h,found); if(found) cout<<"it's found before\n"; else {if(!list.full()) list.insert(h); else cout<<"it's full\n";} break; case (2):if(!list.empty()) {found=false; cout<<"insert the item that you want to delete\n"; cin>>y; h.iniailized(y); list.search(h,found); if(found) {list.deleted(h); cout<<"it's deleted\n";} else cout<<"the item isn't fount to delete it\n"; } else cout<<"it's empty\n"; break; case (3):found=false; cout<<"insert the item that you want to search\n"; cin>>y; h.iniailized(y); list.search(h,found); if(found) cout<<"the item is found\n"; else cout<<"the item isn't found\n"; break; case (4): if(!list.empty()) list.print(); else cout<<"no items to print\n"; break; case (5): list.reset(); break; } } while(x>0&&x<6); }
stack #include const int max=10; class itemtype { private: int value; public: void initialized(int num){value=num;} //all the definitions is in line void print(){cout<}; class stacktype { private: int top; itemtype* info; public: stacktype():top(-1){info=new itemtype[max];} bool full(){return (top==max);} //all the definitions is in line bool empty(){return (top==-1);} void push(itemtype item){top++; info[top]=item;} void pop(){top--;} void reset(){top=-1;} void print(){for(int i=top;i>=0;i--) info[i].print(); cout<}; void main() { int x,y; stacktype stack; itemtype item; do { cout<<"Mohammed Qassim Almolijy\n1)push \t 2)pop \t 3)print\t4)reset\n choose\n"; cin>>x; switch(x) {case 1: cout<<"push the item\n"; if(!stack.full()) {cin>>y; item.initialized(y); stack.push(item); cout<<"the item is pushed\n";} else cout<<"the stack is full\n"; break; case 2: if(!stack.empty()) {stack.pop(); cout<<"the top element is deleted\n";} else cout<<"the stack is empty\n"; break; case 3: if(!stack.empty()) stack.print(); else cout<<"there are not any element to print\n"; break; case 4: stack.reset(); cout<<"the stack is made empty\n"; break;} } while(x>0&&x<5); }
queue #include const int max=10; class itemtype { private: int value; //all the definitions is in line public: void initialized(int num){value=num;} void print(){cout<}; class queue { private: int front,rear; itemtype info[max]; public: //all the definitions is in line queue() {front=max-1;rear=max-1;} void enqueue(itemtype item) {rear=(rear+1)%max;info[rear]=item;} void dequeue(itemtype&item) {front=(front+1)%max;item=info[front];} bool full() {return((rear+1)%max==front);} bool empty() {return (front==rear);} void reset() {front=rear;} void print() {for(int x=(front+1)%max;x<(rear+1)%max;x++) info[x].print(); cout<}; void main() { itemtype i; queue s; int x,y; do{cout<<"mohammed qassim almolijy\n1)add item\t2)delete item\t3)print queue\t4)make empty\t5)exit\nchoose\n"; cin>>x; switch(x) { case 1:if(!s.full()) {cout<<"insert the item\n"; cin>>y; i.initialized(y); s.enqueue(i);} break; case 2:if(!s.empty()) s.dequeue(i); else cout<<"the queue is empty\n"; break; case 3:if(!s.empty()) s.print(); else cout<<"there are not any items\n"; break; case 4: s.reset(); break; default: cout<<"exit..\n"; } } while (x>0&&x<5); }
اتمنى ان تنال استحسانكم
| |
|
اسراء عمر نجم مبدع
عدد الرسائل : 757 العمر : 34 التخصص : نظم معلومات حاسوبية تاريخ التسجيل : 17/11/2008
| موضوع: رد: هنا برامج الداتاستركشر(list - stack - queue ) كاملة الإثنين ديسمبر 15, 2008 11:12 pm | |
| يعطيك الف عافيه يا محمد تقبل ارق تحياتي | |
|
زهرة النرجس نجم جديد
عدد الرسائل : 24 العمر : 33 التخصص : cs تاريخ التسجيل : 17/11/2008
| موضوع: رد: هنا برامج الداتاستركشر(list - stack - queue ) كاملة الثلاثاء ديسمبر 16, 2008 11:41 am | |
| شكرا لك اخ محمد على المساهمه الجيده وبالتوفيق دائما | |
|
salem aldahamsheh نجم فعال
عدد الرسائل : 252 العمر : 36 التخصص : CS تاريخ التسجيل : 24/11/2008
| موضوع: رد: هنا برامج الداتاستركشر(list - stack - queue ) كاملة الخميس ديسمبر 25, 2008 10:28 am | |
| شكرا محمد ع البرنامج الله يعطيك الف عافيه | |
|
Designer مصمم المنتدى
عدد الرسائل : 1558 العمر : 35 مدير المنتدى : 0 تاريخ التسجيل : 20/06/2008
| موضوع: رد: هنا برامج الداتاستركشر(list - stack - queue ) كاملة الإثنين ديسمبر 29, 2008 12:16 am | |
| يعطيك الف عافية على المجهوووووووود الرائع والمشاركة المتميزة ننتظر المزيد من امثال هذه المساهمات وارجو تكثيفها
تحياتي | |
|