Advertisement
MohammedZR21

Untitled

Mar 30th, 2020
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class ListType{
  4. int size,length;
  5. int *list;
  6. public:
  7. ListType(int S=100){
  8. length=0;
  9. if(S>= 0)
  10. size=S;
  11. else size=100;
  12. list = new int [size];
  13. for(int i=0;i<S;i++){
  14.  list[i]=0;}
  15.  
  16. }
  17.  
  18. ~ListType()
  19. {delete [] list;}
  20.  
  21. int getMaxSize()
  22. {return size;}
  23.  
  24. int getLength()
  25. {return length;}
  26.  
  27. bool isEmpty(){
  28.   if (length==0){
  29.   return true;}
  30.   else return false;
  31. }
  32.  
  33. bool isFull(){
  34.   if(length==size){
  35.   return true;}
  36.   else return false;
  37. }
  38.  
  39. void insert(int N){
  40.   for(int i=0;i<size;i++){
  41.   if (list[i]==0)
  42.  { list [i]=N;
  43.   length++;
  44.  break;
  45.     }
  46.   }
  47. }
  48.  
  49. int search(int R){
  50.   for(int i=0;i<size;i++){//or we can change S to L for have more efficiency
  51. if(R==list[i])
  52. {return i;}}
  53. return -1;
  54. }
  55.  
  56. void initialize(){
  57.   delete [] list;
  58.   list =new int [size];
  59.   for(int i=0;i<size;i++){list[i]=0;}
  60.  length=0;
  61. }
  62.  
  63. void print(){
  64.   for(int i=0;i<length;i++){
  65.  cout<<list[i]<<" ";}
  66.  cout<<endl;
  67. }
  68. };
  69.  
  70. int main() {
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement