本文整理汇总了C++中LinkedList::AddLast方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkedList::AddLast方法的具体用法?C++ LinkedList::AddLast怎么用?C++ LinkedList::AddLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList::AddLast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// Demo the use of our LinkedList class.
LinkedList<int> l; // TData is int....
l.AddFirst(1); // ... so all the Add methods take ints.
l.AddFirst(2);
l.AddFirst(3);
l.AddLast(4);
l.AddLast(5);
// Use the .Get method to access individual elements.
// How efficient is this loop? Not as efficient.
// The loop takes too long to walk through all elements of linked lists
// if the size of linked list is large.
for (int i = 0; i < l.Size(); i++) {
cout << l.Get(i) << endl;
}
cout << "Remove: " << endl;
// The .RemoveFirst/Last/At methods return the data removed.
while (l.Size() > 0) {
cout << l.RemoveFirst() << endl;
}
cout << endl;
// It is easy to get the "border" cases wrong in a linked structure. Let's
// test to see what happens when adding to a list that had just been emptied.
l.AddFirst(1);
l.AddFirst(2);
l.AddFirst(3);
l.AddLast(4);
l.AddLast(5);
cout << "After adding back to the emptied list:" << endl;
for (int i = 0; i < l.Size(); i++) {
cout << l.Get(i) << endl;
}
// Does that look correct?
cout << endl;
cout << "Contains 14? " << endl;
// Demo the Contains method. Will this be true or false?
cout << l.Contains(14) << endl;
cout << endl;
// So far we have used the LinkedList directly, so the List base class
// doesn't seem necessary. Through polymorphism, we can declare a List
// pointer to a LinkedList object.
List<int> *p = new LinkedList<int>();
// We can now only call List<int> methods on p... which, fortunately, is all
// of our important functions.
p->AddLast(4);
p->AddLast(8);
p->AddLast(15);
p->AddLast(16);
p->AddLast(23);
p->AddLast(42);
cout << "Pointer to a List contains 16? " << p->Contains(16) << endl;
// So far we don't have much of a reason to do this type of polymorphism.
// But we will...
// Lecture part 2: iterators!
// Picture the normal iterator loop:
// for (_____::iterator itr = _____.begin(); itr != _____.end(); itr++) {
// do something with *itr or itr->
/*
If we want our LinkedList to follow this trend, what do we need to
implement?
1. An inner class named iterator, so our full scoped name will be
LinkedList<TData>::iterator
2. Operators ++, ==, !=, *, and -> in the iterator class.
3. Member methods .begin() and .end() in LinkedList.
When those are implemented, we can then...
*/
cout << endl << "ITERATORS!!!" << endl;
for (LinkedList<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
cout << *itr << endl;
}
}
示例2: ParseLexProfile
bool MetaLexer::ParseLexProfile(const CoreLib::String & lex)
{
LinkedList<LexProfileToken> tokens;
int ptr = 0;
int state = 0;
StringBuilder curToken;
while (ptr < lex.Length())
{
wchar_t curChar = lex[ptr];
wchar_t nextChar = 0;
if (ptr+1<lex.Length())
nextChar = lex[ptr+1];
switch (state)
{
case 0:
{
if (IsLetter(curChar))
state = 1;
else if (IsWhiteSpace(curChar))
ptr ++;
else if (curChar == L'{')
{
state = 2;
ptr ++;
}
else if (curChar == L'=')
state = 3;
else if (curChar == L'/' && nextChar == L'/')
state = 4;
else
{
LexerError err;
err.Position = ptr;
err.Text = String(L"[Profile Error] Illegal character \'") + curChar + L"\'";
Errors.Add(err);
ptr ++;
}
curToken.Clear();
}
break;
case 1:
{
if (IsIdent(curChar))
{
curToken.Append(curChar);
ptr ++;
}
else
{
LexProfileToken tk;
tk.str = curToken.ToString();
tk.type = LexProfileToken::Identifier;
tokens.AddLast(tk);
state = 0;
}
}
break;
case 2:
{
if (curChar == L'}' && (nextChar == L'\r' || nextChar == L'\n' || nextChar == 0) )
{
LexProfileToken tk;
tk.str = curToken.ToString();
tk.type = LexProfileToken::Regex;
tokens.AddLast(tk);
ptr ++;
state = 0;
}
else
{
curToken.Append(curChar);
ptr ++;
}
}
break;
case 3:
{
LexProfileToken tk;
tk.str = curChar;
tk.type = LexProfileToken::Equal;
tokens.AddLast(tk);
ptr ++;
state = 0;
}
break;
case 4:
{
if (curChar == L'\n')
state = 0;
else
ptr ++;
}
}
}
// Parse tokens
LinkedNode<LexProfileToken> * l = tokens.FirstNode();
state = 0;
String curName, curRegex;
try
//.........这里部分代码省略.........