我试图在不使用ListIterator的情况下,定义并实现一个名为insert_back的新操作,该操作接受单个模板Object并在列表末尾插入Object.在不改变此操作或任何其他操作的含义的情况下,我需要修改List的表示并更改使insert_back在常量时间运行所需的任何方法:O(1).
我真的很难实现这一点.
我想创建另一个名为INSERTBACK的菜单选项,它将在列表的末尾插入一个新对象
LIST.H
#ifndef LIST_H
#define LIST_H
#include <iostream>
#include "ListNode.h"
#include "ListIterator.h"
namespace cs20 {
template <class Object>
class List {
public:
List();
List( const List& rhs );
~List();
bool isEmpty() const;
bool isIncreasing() const;
void makeEmpty();
ListIterator<Object> zeroth() const;
ListIterator<Object> first() const;
void insert( const Object& data,
const ListIterator<Object> &iter );
void insert( const Object& data );
void insert_back( const Object& data );
ListIterator<Object> findPrevious( const Object& data ) const;
void remove( const Object& data );
const …Run Code Online (Sandbox Code Playgroud) 我在定义命名空间时遇到了一些麻烦
据我所知,我已经做好了一切
下面是我的代码和构建输出
FlashDrive.h
#ifndef FLASHDRIVE_H
#define FLASHDRIVE_H
#include <iostream>
#include <cstdlib>
namespace cs52 {
class FlashDrive {
friend FlashDrive operator+ (FlashDrive used1 , FlashDrive used2);
friend FlashDrive operator- (FlashDrive used3, FlashDrive used4 );
public:
FlashDrive& FlashDrive::operator=(int);
FlashDrive::FlashDrive(int);
FlashDrive& operator = (const FlashDrive& usedtotal){
my_StorageUsed= usedtotal.my_StorageUsed;
return *this;
}
FlashDrive( );
FlashDrive( int capacity, int used, bool pluggedIn );
void plugIn( );
void pullOut( );
void writeData( int amount );
void eraseData( int amount );
void formatDrive( );
int getCapacity( …Run Code Online (Sandbox Code Playgroud)