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

LIST

مغلق
بدأه Super_emad55 في 23 مارس 2006 · 4 رد · 611 مشاهدة · في لغة C و ++C
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله,

it is very important for any one who likes programing to know how to do lists and sorting lists

so here is the main class of list:

const  int  MAX_LENGTH  =  50;
typedef int   ItemType;

class  List           // Declares a class data type
{      
public:            // Public member functions

    List();           // constructor
    bool IsEmpty () const;
    bool IsFull ()  const;              
    int  Length ()  const; // Returns length of list 
    void Insert (ItemType  item);  
    void Delete (ItemType  item);  
    bool IsPresent(ItemType  item)  const;
    void SelSort ();
    void Reset ();
    ItemType GetNextItem ();  

private:       // Private data members
   int length;   // Number of values currently stored
   ItemType data[MAX_LENGTH]; 
    int  CurrentPos;  // Used in iteration       
};

تنسيق الكود

to make things more interesting, can any one write me the implementation of this class :) < if not i will put it :unsure: , deal>

تم تعديل هذه المشاركة بواسطة Asm4all في 23 مارس 2006 في 00:38

ENG. IMAD, Programing is a way of life, It's in the air, we breath It's pumps through our veines, Without it, we soon crumble to dust

#2
// List.h
const  int  MAX_LENGTH  =  50;
typedef int   ItemType;
class  List { // Declares a class data type
public:            // Public member functions
  List() : length(0), CurrentPos(0) {}; // constructor
  bool IsEmpty() const;
  bool IsFull()  const;
  int  Length()  const; // Returns length of list 
  void Insert(ItemType  item);
  void Delete(ItemType  item);
  bool IsPresent(ItemType  item) const;
  void SelSort();
  void Reset();
  ItemType GetNextItem();
private:       // Private data members
  int length;   // Number of values currently stored
  ItemType data[MAX_LENGTH]; 
  int  CurrentPos;  // Used in iteration       
};

// List.cpp
#include "List.h"

bool List::IsEmpty() const {
  return ((length==0) ? true:false);
}
bool List::IsFull()  const {
  return ((length == MAX_LENGTH) ? true:false);
}
int  List::Length() const{
  return length;
}
void List::Insert(ItemType  item) {
  if(!IsFull()) data[length++] = item;
}
void List::Delete(ItemType item) {
  if(IsEmpty()) return;
  for(int i = --length; i > 0; i--) {
    if(data == item) {
      for(int j = i; j < length; j++)
        data[j] = data[j+1];
      return;
    }
  }
}
bool List::IsPresent(ItemType item) const{
  for(int i = length; i > 0;)
    if(data[--i] == item) return true;
  return false;
}
void List::SelSort() {
  ItemType temp;
  for(int i = 0; i < length; i++) {
    for(int j = length-1; j > i; j--) {
      if(data[j] > data[j-1]) {
        temp = data[j];
        data[j] = data[j-1];
        data[j-1] = temp;
      }
    }
  }
}
void List::Reset() {
  length = 0;
  CurrentPos = 0;
}
ItemType List::GetNextItem() {
  if(CurrentPos < length) return data[CurrentPos++];
  return 0;
}
#3

Good programer ;)

ENG. IMAD, Programing is a way of life, It's in the air, we breath It's pumps through our veines, Without it, we soon crumble to dust

#4

مشكور اخي Asm4all وSuper_emad55 علي الموضوع المفيد

وجزاكم الله خيرا علي المجهود

تم تعديل هذه المشاركة بواسطة khaled_tiger في 24 مارس 2006 في 19:56

Khaled_Tiger

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

يخاطبني السفيه بكل قبح *** فأكره أن أكون له مجيبا

يزيد سفاهة فأزيد حلمــا *** كعود زاده الإحراق طيبا

إذا نطق السفيه فلا تجبه *** فخير من إجابته السكوت

فإن كلَمته فرَجت عنــــه *** وإن خليته كمداً يـمـــوت

#5

تسلم اخوي khaled_tiger

ENG. IMAD, Programing is a way of life, It's in the air, we breath It's pumps through our veines, Without it, we soon crumble to dust

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

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

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

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

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

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