首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
C/C++程序语言调试、辅导program编程设计、辅导CS,c++程序 辅导留学生 Statistics统计、回归、迭代|调试C/C++编程
项目预算:
开发周期:
发布时间:
要求地区:
Assignment 6
Question 1
In this question, you are required to implement a hashmap of strings.
The required strategies are:
Open Addressing: When a hash collision happened, find another available slot to store the
key-value pair
Linear Probing: In finding another available slot, using linear probing; that is to check
slot[current + 1 % capacity] until found an available slot.
Dummy Erasing: A problem for open addressing is that remove an key-value pair from the
map will result in an empty slot which will affect the linear probing procedure. A common
workaround is to make a special mark to the deleted entry such that it can be reused later
but the probing procedure should not stop.
Detailed requirements are in the comments of the template code. Please have a careful look.
The required interfaces are
/*
* return_type operator[] ( const std::string & key ) const
* ---------------------------------------------------------
* Get a reference to the value associated with the key if it exists in the
hashmap.
*
* - Return `std::nullopt` if the key does not exist
* - You can use `std::ref ( value )` to create a `std::reference_wrapper`
* to value
* - See https://en.cppreference.com/w/cpp/utility/optional for documents of
`std::optional`
* - See
https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper for
documents
* of `std::reference_wrapper`
* - See https://en.cppreference.com/w/cpp/utility/functional/ref for
documents of `std::ref`
*/
return_type operator[] ( const std::string & key ) const;
/*
* void insert ( const std::string & key, const std::string& value )
* ------------------------------------------------------------------
* Insert a new item to the hashmap.
*
* - If key exists, simply replace the value.
* - Otherwise, if `load_factor ( ) >= MAX_LOAD_FACTOR`, do `rehash ( )`
first
* - Then use linear probing and open addressing to locate a new bucket for
the key-value pair
*/
void insert ( const std::string & key, const std::string& value );
/*
* void erase ( const std::string & key )
* ------------------------------------------------------------------
* Erase an existing key-value pair
*
* - If the key exists, remove the key.
* - If the key does not exist, do nothing.
* - If this operation results in an empty slot in the middle, the
* handling strategy is to mark the slot as dummy to make sure that
* later probing can be done successfully.
*/
void erase ( const std::string & key );
/*
* bool contains ( const std::string & key ) const
* -------------------------------------------------------------------
* Check whether the hashmap contains the given key.
*/
bool contains ( const std::string & key ) const;
/*
* bool empty ( ) const
* -------------------------------------------------------------------
* Check whether the hashmap is empty or not.
*/
bool empty ( ) const;
/*
* size_t size ( ) const
* -------------------------------------------------------------------
* Return the size of the hashmap (number of used buckets)
*/
size_t size ( ) const;
/*
* size_t capacity ( ) const
* -------------------------------------------------------------------
* Return the capacity of the hashmap (number of all buckets)
*/
size_t capacity ( ) const;
/*
* void clear ( )
* -------------------------------------------------------------------
* Clear all hashmap entries and reset capacity to default.
*/
void clear ( );
/*
* void rehash ( )
* -------------------------------------------------------------------
* Grow the hashmap capacity to 3 times (we should have `3 * original`
* capacity after this operation) and rehash all existing entries.
*/
void rehash ( );
Question 2
In this question, you are required to implement a priority queue using binary heap. You should
not use the binary heap related functions from STL.
The required interfaces are
/*
* float load_factor () const
* -------------------------------------------------------------------
* Get the load factor of the current hashmap.
*/
float load_factor () const;
/*
* Copy Constructor
* -----------------------------------------------------
* Copy construct a new priority queue. You should write
* it correctly on yourself.
*/
PriorityQueue ( const T& that );
/*
* Copy Assignment Operator
* -------------------------------------------------------
* Copy Assignment the priority queue. You should write it
* correctly on yourself.
*/
PriorityQueue & operator= ( const T& that );
/*
* void push ( const T& element )
* -------------------------------------------------------
* Push a new element to the priority queue.
*/
void push ( const T& element );
/*
* T pop ( )
* -------------------------------------------------------
* Pop the element with the highest priority in the queue.
* and return it;
* No need for checking whether the queue is empty.
*/
T pop ( );
/*
* const T& top () const
* -------------------------------------------------------
* Return a reference to the element with the highest
* priority.
* No need for checking whether the queue is empty.
*/
const T& top () const;
/*
Question 3
In questions 3, you are going to help us complete the implementation of a Graph class.
The graph is directed. The basic constructors and structures design are provided.
The graph is organized in std::unordered_map < std::string, Node > inner , you can use
inner.at(name) to visit a specific node.
Each node is something like:
You can access the connected node via
You need to finish the implementation of the following interfaces:
* bool empty () const
* -------------------------------------------------------
* Check whether the queue is empty
*/
bool empty () const;
/*
* void clear ()
* -------------------------------------------------------
* Clear all elements in the queue
*/
void clear ();
/*
* size_t size () const
* -------------------------------------------------------
* Return the size of the queue.
*/
size_t size () const;
using NodePtr = struct Node *;
struct Node {
std::string name;
std::vector < NodePtr > edges;
explicit Node ( std::string name );
};
for (Node * i : inner.at(name).edges) {
std::cout << name << " -> " << i->name << std::endl;
}
/*
* std::vector< std::string > dfs_order ( const std::string & root ) const
* --------------------------------------------------------------------
* Using `std::stack` to run DFS.
* Return the DFS order starting from the root.
*
* - The order is recorded when a node is pushed to stack
* - For edges, please visit them in the order as they are in the vector.
File Tree
We will deliver an archive with the following structure, when submitting, please also keep the
same structure.
* - Already visited nodes will not be pushed to stack again.
* - For details, see examples.
*/
std::vector< std::string > dfs_order ( const std::string & root ) const;
/*
* std::vector< std::string > bfs_order ( const std::string & root ) const
* --------------------------------------------------------------------
* Using `std::queue` to run BFS.
* Return the BFS order starting from the root.
*
* - The order is recorded when a node is pushed to queue.
* - For edges, please visit them in the order as they are in the vector.
* - Already visited nodes will not be pushed to queue again.
* - For details, see examples.
*/
std::vector< std::string > bfs_order ( const std::string & root ) const;
.
├── lib
│ └──
# do not modify
├── res
│ └──
# do not modify
├── Assignment-6.pro # do not modify
└── src
├── testing
│ └──
# do not modify
├── graph.cpp # change it
├── graph.h # do not modify
├── priorityqueue.cpp # do not modify
├── priorityqueue.h # change it
├── main.cpp # change it
├── stringmap.cpp # change it
├── stringmap.h # do not modify
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写math 1151, autumn 2024 w...
2024-11-14
代做comp4336/9336 mobile dat...
2024-11-14
代做eesa01 lab 2: weather an...
2024-11-14
代写comp1521 - 24t3 assignme...
2024-11-14
代写nbs8020 - dissertation s...
2024-11-14
代做fin b377f technical anal...
2024-11-14
代做ceic6714 mini design pro...
2024-11-14
代做introduction to computer...
2024-11-14
代做cs 353, fall 2024 introd...
2024-11-14
代做phy254 problem set #3 fa...
2024-11-14
代写n1569 financial risk man...
2024-11-14
代写csci-ua.0202 lab 3: enco...
2024-11-14
代写econ2226: chinese econom...
2024-11-14
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!