首页 > > 详细

C++辅导Doubly Linked List 程序、Felina讲解C/C++编程、C/C++讲解

Doubly Linked List,STL。Doubly Linked List,。
 

Background

In this project, you will write the implementation of the PeopleList using a doubly linked list. You will also implement a couple of algorithms that operate on a PeopleList.

Implement PeopleList

Consider the following PeopleList interface:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
typedef std::string InfoType;

class PeopleList
#123;
public:
PeopleList(); // Create an empty In (i.e., one with no InfoType values)

bool empty() const; // Return true if the list is empty, otherwise false.

int size() const; // Return the number of elements in the linked list.

bool add(const std::stringamp; firstName, const std::stringamp; lastName, const InfoTypeamp; value);
// If the full name (both the first and last name) is not equal to any full name currently
// in the list then add it and return true. Elements should be added according to
// their last name. Elements with the same last name should be added according to
// their first names. Otherwise, make no change to the list and return false
// (indicating that the name is already in the list).

bool change(const <㱳⽰㹬㱡⽳㹵㱩 ⽩㹮㰢‼㴾∺≡㹮†⁣⁡⁳⁳㰽㴾≳≳㹰⽡⽮‾※⁲‬⁳†‽‾⁳⁡㱵⽩㹮㰢⼾㸯㱳⼾㸺㰺㵳∽≬㹴 ⁩•‾⁳㱴‼㴾∠≴㹎⽡⽭⁥⹡㱮⼠㹳㰽⼢㹯㱲‾⽣㹯㱮‼⼯㹳㱰⁉㵰≥∠㹶⁡⁵⁥㰩⁡㵰≡≮㸾㰼‾㴠≣≩㹮㰠⼠㹳⁰㱡⁡㵯≭∾㸯㱦⼠㹦㱵⁡㴠≥≯㸠⡡㰠†㵣≵∠㹩㱨⽥㹴‬ⱴ⁨㱥㵴∠≰㹡㰯⽳㸼㩢㩲㰠⁰㵡≳∾㸠㱳⽰㹬㬽•Ⱟ 㰠†㵮≧≯㸠㰠⽶㸠㩩㩴㰠⁥㵭≡≵㹴㱡⽤㸠㬯⁳ⱡ䤾㭮†⤽㰢⽬㸾†㰠‼㵣≬≭㹭㰯⼯㸠㱶⽡㹯㭦㰠⽴㹨㱩†⽰㹡㱲⁥㵴≵≲㹵⁥†⁩†⁴㱨⁡㵳≰≡㹮⼾⼼⁢䥲 〾‼㭡㵮†㭳‽⡥⤢ⰾ††Ɐ†⁥‬⁨㱥⼠㹨㱥⼠㸠㱡†⽲㹥㱴⁦㴼∯∾㸼 ⁳⁰⁡‾㰼‾㴾∼≡㹳⽳⼽•⁡⁩‾⁳⁤‾⁳†⁡㱳⼽㹬㱥⼢㹏㱲⁡⽮㹧㱥⁡㵡≮≳㹳‽•⁰⁡⁲⁡㱭‼㵣≬≩㹬⽴⽟⁩⹴⁤‼ⱳ⁰⁡•⁳⁡⁦⹰⁡㰠⽣㸽㰢⽢㹟㱩‾⽳㹴㱤⁡㵳≰≬㹡⁳⁳‽•⁢⁵㱩㵩≮∾㸠⽬⽡⁳⡴⁥⁡⁹‾⁴⹉⥮㱦⽯㹡㱭⽰㹬㱵‼⼯㹳㱰 㴻∼≮㸾‼⁢⁲† ‾‼⁳⁰⁡㱮⼠㹳㰽⁩⽮㹥㰢†㵡≮≳㹳‽•⁣㱭•㵦∠≥㸠㱩⁵㴠≡≵㹲㱬⽹㹴⁨㱥⁴㵮∠≴㹨㱵⽬㹭㱥 㴼∯≢㹲⠠䱮㬽•⤾㰠⼠㸼㱳⽰㹬㭡㱳⽳㹭㱭⁴⼢㸾㰯㵡≰≴㹨⁥†⁶⁡⁵㱥⁣㵴≬≴㹯⼬⼠⁢䕵⁡⁡⁡‼†⁰⁣•⹥㰢⼾㸠㰠⼼㸠㱣⁳⽳㸽㰢⁥㴯∠≶㹡⍬ㅵ㉥㔠㭯㭦㰠⽴㹨㱩†⽰㹡㱲⽡㹥൲਻†⁲⁥⁴⁵⁲†⁴⁲⁵⁥㰠⽩㹴൨੩⁳†⁣⁡⁳⁥‮‼㰯⽳㹮ാ਼ ⁳⁰⁡㱮⼾㸾഼ੳ㱰⽡㹳൳਽㰢⽬㹮൥ਢ㰾㸠†⁡• ⁨⁡†⁳⁴⁡⁡††⸠⁣䥵⁲†⁴⁴†‼⁡⁳‼‾⁳Ⱐ†‼⁳ⱴ•†⁥‮†⁦⹩䥮⁡†Ɱ⁳⁥⁰㱮⁢⽲㸠യਾ㰼⁳㵬≡‾⬠⬠∠㸼㱳⽰㹳൳਽㰢㹩൯੮•‾‼⁳㱰㹡൳ੳ‽•⁥⁹⁷⁲㱤㹢൯੯‼ ⁳⁰⁡‾†‼⁳⁰㱡⁣㴢≴≲㹥൭੯⁶⁥‼ ⁳⁰⁡‾‼⁳⁰㱡㹬㱡⁰㴢∾≡㹮ㄠ㱣⽬㸢㱫⁷⽯㹲㱤㵰≡≳㹰㉡㱮⼠㹳㰽⁵⽩㹬㱴‾㵳≰∺㸼㍳㱰⽡㹡㱳•⽢㹵㱩㵩≮≰㹡㑮㰾⽡㹦㱩⁴⽎㹡㱭㵰≡≡㹳㕳㰽⼢㹴㱟•⼾㹳㱴⁰㴼≳≣㹬㙡㱳⽳㹩㱬⁩⽮㸢㰾㵡≮∻㸠㝬㱡⽳㹥㰩⁳⽰㹡㱮⁰㴯≳∼㹢㡲㰠⼯㹡㱮⽡㹳㱳㴠∠≰㹡㥮㰠⽣㸽㰢⽭㹥㱮 㵨≥≬㸠ㅮち㱭⽥㹥㱱⼠㹴㱯⁵㵭≥≲㹥ㅮㅴ㱬⽹㹴㱨⽩㹳㱴㵨≥≰㹡ㅮ㈾㰼⼯㸾㰼†⼯㸾㰼†㴽∢∢㸾ㄠ㌠㰠⼠㹰㱡⁣⽬㹡㱳㴢∾≵㹬ㅬ㐠㱮⽡㹮㱤⁡⽬㹵㱥㵬≩≮㹤ㄠ㕲㱥⽴㹴㱲‮⼠㸠㱏⁷㵭≡≳㹰ㅡ㙮㰾⼼㹮㰾⁲⼠㸯㰾⼼㹮ഠ੣⁡⁳⁳‽•⁩⁥•‾㰠⼠㸠ഠ਼⁳⁰⁡†⁣⁡⁳⁳‽•㱣㴯∯≣㹨ൡ੮⁧⁥†⁴†⁴⁨⁥†⁩㱳㹮㱤⁵㵬≳≳㹰䱰‼㭲㰠⼯㸠㰯⁳⽰㹡㱮⽡㹳㱳㴠∠≮㸠⹬⠽㰢⁴㴼≳≡㹳♳㭹♢㬯㱳⽰㸼ⱳ⁰㱡⁡㵩≴≮㹴♡㬯☼㬠㱣⽬㸢Ɒ⁡㱲‾㵮∠∢㹫㑥㕹㱷⽯㹣⥯㭮㱳⽴㹡㱮‼⽳㹰㱡⁡㵵≩≮㸢⹳⠯㱳›㵮∠∢㹢♵㭩䩮♲㬯㱳⽰㹦Ⱪ⁲㱳⁥㵡≮∽㸢♫㭲䵤䜾♳㭰㱡⽮㹰ⱡ㰠⁳㵬≴≴㹤㐼㤯㱳⽰㸺⤼㭳㱰⽡㹡㱳•⽢㹵㱩㵩≮≰㹡⸾⡳㱴
㵮∾∠㹣♬㬢䍫☢㭳㱴⼼㹮ⰾ‼㰯‾㵡≮∾㸼♳㭣䵬䝳♬㬾㰠⼠㸼ⱳ⁰㱡⁡㵯≭∯㸯㔠㡒㱥⽴㹴⥲㭵㱥⼠㹨㱥⁵⽬㹬㰠†㵵≡∠㹡⹦⠠㱮⁣㵴≬≨㹥☠㬬♷㬯㱳⽰㸯ⱳ⁰㱡⁲㵰≡≳㸽☢㬢☠㭡㱮⼠㹳ⰽ•㱣㴠≦∯㹳㕰㉡㱮⼾㹡⥮㬾㰼⽢㸼㱢 ⼾㸼㱳⁣㴢≬∾㸠⸠⡰㱡⁡㵵≮∾㸼♳㭣䩬☢㭯㱲⽤㹯ⱬ‼㰯‾㵮∠∢㹴♩㬾☯㬾㰼⽳㹣ⱬ⁡㱳⁡㴾∨≣㹬㉡㝳㱳⼽㹷⥯㭲㱤⼢㹳㱴⁳⽰㹡㱮‼⽳㹰㱡⁡㵵≩≮㸢㰾 㴺∺≬㹡㰢⽢㹟⁩⡮㰢⁩㵰≡≦㹩㱎⽡㸼⁳⁡㵮†㱣‽㵯≲≳㹴〼㰯⽳㸠㬼⁳⁡㭣⹳⡵⥩㭬⁴⭩⭮⤢㰾⽳㹳㱰‾⼺㸺㰼†㴽∢≴㹟⍩ㅮ㈢㌾㭳㱴⽲㸯㱳⼾㹡㱭⁡㵥∬≯㹔⁹⁰⁥⁡㱭⁡㴯≳≡㹮㰽⼢㹯⁲㬢㰾⽣㸼㰯⁡⽮㸾㰼㵰≡≲㸠 ‾‼⁳㱰㵬≩∠㸠㱣⽬㸢⁣㭭㱭⽥㸯㰯⁦⼠㹴㱨㵥∠≱㹵⁡†⁴㱯⁵㵭≥≴㹬㱮⼠㹬⁩㭴㰬⼠㹶㱡⁥⼠㹴㱯‼㴾∼≮㸾‼⁢⁲†⸾⡡Ⱐ⁣ⱡ⁳ⰽ•⥩㭮㱥⼢㸠㰠⁳⽰㹡㱮⁳㵭≭∾㸯 †⁶⁡㱬㵬≩≴㹨㱵⽬㹭⁥㭡㬠⁴‬㭮㭲⁥㱴⁴㴠≏≳㹥☬㭥♥㭳㰠⽩㹥†㭯㭥⁌⁳㬨㬠⁡㱤⁨㵳≨≬㹷♡㭥⁴♵㭲㱵⽥㹬⁳㬠㬠⁡⁐㭰㭌⁩㱳⁳㵺≥≨㹥㱥⼠㹥㭳㰠⽯㹥㰠⁲⽳㹴㰠㵴≯∠㹧⍥ㅴ㈠㕭㭥㱭⽢㹵㱮⁩⽯㹮㰠⽡㸰ബਠ‱‬†′‬†…⁨⁥⁩㱰⼻㹮ഭ਱※†⁦⁲†⁴㱨⽥㹶ൡ੬⁵⁥⁳‬㰠⽩㹵൲੮㱳⼠㸠൷੩㱴⽨㹵൴ਠ㱳㹴†⁲⁥⁳㨊㰼⽨㸠൩੤㰽㹰㱬㹴䌭䵮䝭⁥㕲㠭൦ੵ䩮䵳䜾㑥㥭൥੮䩴⁥㉢㝥൲ਠ′㐾㔍ഊ਼⁧†㕴㉨൥ਠ㱰⽵㸠㱩⽮㹦ൡ੣㱥㹯⁴⁦⁧⁷⁴
⁴†㭴⁨⁡‭⁢⁩⁳⁨㩭㱥⁥⽲㹳ഠ੯㱦⁥㵯≲⁲⭣⭬≡㹳㱳⼮㸾഍ਊ㰼㹥ഠ੣⁡⁳⁳㰽㹬൩੧⁨⁴†⁣‫‫•‾㰼㹩൧ੵ⁲⁥‾‍ ‼⁴⁡⁢⁥‾㰍†㵯≤∠㸠ഠਠ††‼⁴⁲‾‍ ††††㰠㸠㰠⁤㵳∽≴㹥ㅲ㰢⼾㸠㰠†⼠㸠㰠⁲㵡≮≳㹳㈽㰢⽬㸾㰱⁳⽰㹡㱮†㵲≥∠㸠㌠㰠⼠㸠㰠⁴⽤㸾㰍†㴠∠∠㹣㑬㱡⽳㹯㱤‾⼍㸊㰠†㴠∼∼㹳㕰㱡⽮㹳㱳⽩㹮㱥⁰㵡≳≵㹮㙣㱴⽩㸼㱳⼠㹣㱬•㵲≤≯㹬㜼㰯⽳㸠㰼⁡⽮㸠㱣‽㵥∢≢㹩㡮㱥⼼㹮㰾⁰⽡㹮㰠⁳㵡≭∼㹳㥰㱡⽮㹳㱳⽥㹹㱷‾㴼∯∾㸠ㅐづ㱯⽰㹳㱴⁰⼻㸠㱭⁳㵬≡≫㹥ㅹㅷ㱯⽲㹯㱮‼⼯㹳㱰⽡㹐൥੯⁰⁥⁌⁩⁳⁴⁡⁰※†㱭⼲㹐൥੯⁰⁥⁌⁩⁳⁴⁡⁰※†㱲⁵㵳≰∯㹳൰੡‾※‼ ⁳⁰⁡‾‼⁢㱲㸼㰯‍㴠∠∠㸠䰊†㬼㰯⽴㸠㰠‼⼯㹴㱢⁹⼾㸍㰊⁢㴼∯∼㹰⹮⡩㱳⁣㵲≥∠㹲♥㬠䝭♴㭳㱩⽳㸠Ɒ⁡㱩⁥㵮≥≨㹥♳㭬䙥♰㭵㱬⼾㸠Ⱐ‼㱬†㵬∠≰㹰㍥⹡㝲㕳㘠㱩⽮㹣⥴㭬㱹⼠㹯㱦‱⼠㹡㱮‬㴠≲≴㸠⡯Ⅾ⸠⡮㱴⁳㵧∠≴㸠♦㭮♡㭮㱤⼠㹣Ɐ㱲㴠≶∯㹬♩㬠☠㬾㱉⽦㹵⥬⥬㬠㱮⽡㹰㱰⁲⽳㸠㱩⁴㵡≮∬㸠⸠⠠㱳⁣㵰≯≶㹡♬㭮䨠♨㭥㱮⼠㹬ⱴ†㱭⁣㵮∠≭㹥♮㭴䵨♵㭡㱭⽥㸠ⱶ⁡㱬 㴼∯≰㸾㍗⹨㕥㍮㠠㱴⽨㹵⥮㭣㱴⽩㹥㱴⽳㸬㰠㵴∠≡㹩⸠⡭㱥㵴≨≳㹥☠㭩♲㭹㰠⽴㸠Ⱳ⁵㱬
㵵≳≡㹳♳㭲♥㬠㱩⽳㹴ⱹ†㱷⁩㵰≡≮㸠㑴⹯〠ぴと㱩⽳㹣⥴㭩㱯⽮㸠㱭⁨⽴㸠㱮⁥㴾∍≉㹦⹲⡸㱩⁡㴠≮≡㹴☠㭡䩲☠㬠㱭⼱㸠Ɑ′㰬†㵤≩≴㸠♣㭳☠㭥㱳⼬㹮Ⱐ⁴㱨⁵㵮∠≳㸠㉦⹡㉬㕳㙥㰻⼠㹨⥥㭲㱥⼠㹯㰠⽬㸠㱮㵨≩≨㹥⡩⹥⡵㱥⁥㵴≨≴㹩♯㭴♵㭦㱡⽬㹲ⱥ⁳㱵⁵㴠≣≵㹴♥㬠♤㭥㱤⼠㹨⥥⤠㭡㱢⽯㹵㱬‮⼼㸯㱰⁰㵥≸≥㸬⹰⡐㱥⁌㵡≰≦㹵♬㭭䝥♯㭥㱧⽥㹉ⱦ†㱭㴠≯≥㸠♴㬠䙥♮㭰㰾⼍㹥⤾㬼㱣⽯㹵㱯⁅⽴㹨㱥⁴㵴∻≺㹱⠴⸠⡵⥯⁴㴻㵆⁲㱥⁴㵴∻≵㹯㍴㰻⼠㸠††㭱㬻⁌⁵⹯⡒㱩㴠∠∯㹣♯㬯䩰☊㭮㱤⼠㹯Ɱ⁳㱩㴍∊≣㹯♤㭯♵㭱㱵⽯㹣⥡⁲⁤㭯㬠㰷⼸㸠㰠⁵⽯㹴㰻⁹㴠≱≒㹩⁣⁡⁲⁤ⁱ⸠⡯㱤⁰㴼≰≮㹯☠㭥䩲♡㭬㱵⽥㹨ⱡ⁤㰠⁲㵳≵≴㸠♥㭰䴠♳㭮㱳⽩㹧⤠⁦㬾㭰⁲⹯⡅㱴⁵㵵≯≺㹱♵㬠☴㬠㰠⼠㸻ⱆ⁲㱥⁴㵴∻≵㹯♴㬲☳㬠㰠⼠㸻⥌⥵㭣㱹⽱㸠㱱⁴⼻㹒㱩⽣㹯൱ੵ⁴※††‷‸‹††††㰠⼠㹯൴਻⁒⁩⁣⁹ⁱ⁵㱴⼻㹵൯ੴ※⁒⁩⁣㱡⽲㹴഻ਠ㰠⼳㹣൯੤㱥⼾㸯൰ੲ㱥㸍⁡⁥⁴⁴Ⱐ⁴ⱦ†䍡Ⱐ⁷Ⱐ⁢Ɱ⁤†ⱴ⁥‼‍⁲㵥㴾‼⁤Ⅵ㴾ⁱ⁵※⁡ⁱ‵†ⁱ※⹯⁴⁴⁩ⵯ‱Ɒ⁲ ♨㬠⁡⸠㱷⽨㹴ഠ੶㱡㹵䙥⁴†Ⱐ⁲⁴†䱡⁳⁩‼⁰ⵥ‾⸻⁅⡴ⁱ†⁴⁲⁵††⁵䍯⭴⬻⁆⸻⤠㱱⽵㹴഻੍㱥㹴䙺‱Ⱪ⁣ⁱ※⁩⁴‱ ⰾ‍⁡Ɑ⁵⁲⁥Ⰺ‼⁲⁡‽⁧⁴ⰾ‼⁩⁥⁴‾†⁤ ⁴†††⁴⁲㨠㰠⼠㸠ഠਠ㰠㌠†㵰≲䑥≡㹳䑳㰼⼯㍰㹡൮ਾ㰼㹲⁳⁡䱳⁩•ⰼ⁢‾ ††⁴⸠㰠⼠㸠഼ੴ㱤㍣㵳∽䌢ⵥ∠㸠䌠⁰㱡⽳㌽㸢൬੩㱮㸢⁡†‽䰾⁡⁣⁥⁤⁩ ⁡†䰢ⱬ⁥‾⁣⁰⁰†⹳㰽⼢㹡൲੡㱭㌢‾㵳≰䅡⵫≣㹯䅮†㱡⽳㌽㸢ൢੵ㱩㹴‾⁤›䱣⁳⠽⁩⵮⁲⤯⁳⁥⁨⁡⁣⁥䰾⁳⡴⁰⵳⁣⤽Ⱒ⁢⁴⁴⁰‾⁰⁣ⴽ•⁧⁳⁡⁥⁣‼ⴾ ⁡ⱳ‽⁥†††⠼⹰⹮†⁡⁹• †⁌⵭‱⁴⁰⁵‾⁰⥢⹲㰠⼯㸼യੰ㱲㸾††⁤ ††⁲† ⁤⁡

When this function returns, result must contain a copy of all the elements in m1 that match the search terms; it must not contain any other elements. You can wildcard the first name, last name or both by supplying “*”. (You must not assume result is empty when it is passed in to this function; it may not be.)

For example, if p consists of the three elements

quot;Gustavoquot; quot;Fringquot;  57      quot;Skylerquot; quot;Whitequot;  45      quot;Walterquot; quot;Whitequot; 52 

and the following call is made:

search(quot;*quot;, quot;Whitequot;, p, result)

then no matter what value it had before, result must end up as a PeopleList consisting of

quot;Skylerquot; quot;Whitequot;  45       quot;Walterquot; quot;Whitequot; 52

If instead, p1 were

quot;Janequot; quot;Doequot; 35            quot;Mariequot; quot;Schraderquot; 37      quot;Janequot; quot;Margolisquot; 27

and the following call is made:

1
search("Jane", "*", p, result)

then no matter what value it had before, result must end up as a list consisting of

quot;Janequot; quot;Doequot; 35            quot;Janequot; quot;Margolisquot; 27

and if the following call is made:

1
search("*", "*", p, result)

then no matter what value it had before, result must end up being a copy of p

Be sure these functions behave correctly in the face of aliasing: What if m1 and result refer to the same PeopleList, for example?

 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!