Vous êtes sur la page 1sur 17

pq_with_id.

pdf
fkj1.pdf

In class exercise:
Please design a priority queue data structure, priority_queue_with_id, that allows the user to
modify priority and delete a data with a specific id efficiently. You can modify code from
cp::priority_queue. It should have the following structure
template <typename T, typename Comp = std::less<T>>
class priority_queue with_id {
protected:
T*

mData;

size_t mCap;
size_t mSize;
Comp mLess;
// TODO: Your additional variables here
public:
priority_queue with_id (const Comp& c = Comp())

{ ... }

priority_queue with_id (const pr priority_queue with_id<T,Comp>& a) { ... }


~priority_queue with_id () { ... }
//------------- capacity function ---------bool empty() const

{ ... }

size_t size() const

{ ... }

//----------------- access ----------------const T& top() const

{ ... }

const size_t& top_id() const

{ ... }

//----------------- modifier --------------size_t push(const T& e) { ... } // return id


void pop()

{ ... }

void changeData(size_t id, const T& new_e) { }


void deleteData(size_t id) { }
// TODO: Your additional functions here
};

Hint: You can use stl::map to help, and achieve O(log2 n) or you can do better and be
O(log n)

Bad.pdf
kdil.pdf

pq_with_id.pdf
asdafg.pdf

In class exercise:
Please design a priority queue data structure, priority_queue_with_id, that allows the user to
modify priority and delete a data with a specific id efficiently. You can modify code from
cp::priority_queue. It should have the following structure
template <typename T, typename Comp = std::less<T>>
class priority_queue with_id {
protected:
T*

mData;

size_t mCap;
size_t mSize;
Comp mLess;
// TODO: Your additional variables here
public:
priority_queue with_id (const Comp& c = Comp())

{ ... }

priority_queue with_id (const pr priority_queue with_id<T,Comp>& a) { ... }


~priority_queue with_id () { ... }
//------------- capacity function ---------bool empty() const

{ ... }

size_t size() const

{ ... }

//----------------- access ----------------const T& top() const

{ ... }

const size_t& top_id() const

{ ... }

//----------------- modifier --------------size_t push(const T& e) { ... } // return id


void pop()

{ ... }

void changeData(size_t id, const T& new_e) { }


void deleteData(size_t id) { }
// TODO: Your additional functions here
};

Hint: You can use stl::map to help, and achieve O(log2 n) or you can do better and be
O(log n)

dummy.pdf

This is a dummy PDF

pq_with_id.pdf
Bad.pdf

In class exercise:
Please design a priority queue data structure, priority_queue_with_id, that allows the user to
modify priority and delete a data with a specific id efficiently. You can modify code from
cp::priority_queue. It should have the following structure
template <typename T, typename Comp = std::less<T>>
class priority_queue with_id {
protected:
T*

mData;

size_t mCap;
size_t mSize;
Comp mLess;
// TODO: Your additional variables here
public:
priority_queue with_id (const Comp& c = Comp())

{ ... }

priority_queue with_id (const pr priority_queue with_id<T,Comp>& a) { ... }


~priority_queue with_id () { ... }
//------------- capacity function ---------bool empty() const

{ ... }

size_t size() const

{ ... }

//----------------- access ----------------const T& top() const

{ ... }

const size_t& top_id() const

{ ... }

//----------------- modifier --------------size_t push(const T& e) { ... } // return id


void pop()

{ ... }

void changeData(size_t id, const T& new_e) { }


void deleteData(size_t id) { }
// TODO: Your additional functions here
};

Hint: You can use stl::map to help, and achieve O(log2 n) or you can do better and be
O(log n)

pq_with_id.pdf
asdafg.pdf

In class exercise:
Please design a priority queue data structure, priority_queue_with_id, that allows the user to
modify priority and delete a data with a specific id efficiently. You can modify code from
cp::priority_queue. It should have the following structure
template <typename T, typename Comp = std::less<T>>
class priority_queue with_id {
protected:
T*

mData;

size_t mCap;
size_t mSize;
Comp mLess;
// TODO: Your additional variables here
public:
priority_queue with_id (const Comp& c = Comp())

{ ... }

priority_queue with_id (const pr priority_queue with_id<T,Comp>& a) { ... }


~priority_queue with_id () { ... }
//------------- capacity function ---------bool empty() const

{ ... }

size_t size() const

{ ... }

//----------------- access ----------------const T& top() const

{ ... }

const size_t& top_id() const

{ ... }

//----------------- modifier --------------size_t push(const T& e) { ... } // return id


void pop()

{ ... }

void changeData(size_t id, const T& new_e) { }


void deleteData(size_t id) { }
// TODO: Your additional functions here
};

Hint: You can use stl::map to help, and achieve O(log2 n) or you can do better and be
O(log n)

dummy.pdf

This is a dummy PDF