Answer to Question #269686 in C++ for Roe

Question #269686

Call the functions in main.


Using dynamic array implement the following :



1. Create the list. The list is initialized to an empty state.







2. Determine whether the list is empty.







3. Determine whether the list is full.







4. Find the size of the list.







5. Destroy, or clear, the list.







6. Determine whether an item is the same as a given list element.







7. Insert an item in the list at the specified location.




1
Expert's answer
2021-11-22T09:54:22-0500
#include<iostream>
using namespace std;
class list11 : public List {
  Litemtype* lisArray;           
  static const int DEFAULT_SIZE = 10;
  int maxsize;                        
  int listsize;                      
  int current;                          




public:




  AList(int S = DEFAULT_SIZE) :listsize(0), curr(0) {
     maxsize = S;
    lisArray = new ListItemType[S];     
  }
  
  ~list11() { delete [] lisArray; }     








  void clear() {listsize = current = 0; } 








  bool insert(const Litemtyp& it) {
    if (listsize >=  maxsize) return false;
    for (int i = Lsize; i > curr; i--)  
      lisArray[i] =lisArrayr[i-1];      
    lisArrayr[current] = it;
    return true;
  }




  bool append(const Litemtype& it) {
    if (listsize >= maxsize) return false;
    lisArray[listsize++] = it;
    return true;
  }








  Litemtype remove() {
    if ((current < 0) || (current >=listsize))
      throw std::out_of_range("current of" + to_string(current) + " and size of "
        + to_string(listsize) + " invalid element");
    Litemtype it = lisArray[current];    
    for(int i = current; i < listsize-1; i++)
      lisArray[i] = listArr[i+1];
    listsize--;                            
    return it;
  }




  void moveToStart() {current = 0; }       
  void moveToEnd() {current = listsize; } 
  void delete(){cout<<"Enter the item to delete: ";
  cout<<"Item successfully deleted: ";
  }
  void prev() { if (current != 0) current--; } 
  void search(){
  }
  
  void next() { if (current < Lsize) current++; } 
  int length() { return listsize; }    
  int currPos() { return current; }        




 
  bool moveToPos(int pos) {
    if ((pos < 0) || (pos >listsize)) return false;
    current = pos;
    return true;
  }




  bool isAtEnd() { return current == listSize; }




  
  Litemtype getValue() {
    if ((current < 0) || (current >= lsize)) 
      throw std::out_of_range("current " + to_string(current) +  + " and size of "
        + to_string(Lsize) + "invalid element");
    return lisArray[current];
  }
 
  bool isEmpty() { return listsize == 0; }
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS