本文整理汇总了C++中SortedList类的典型用法代码示例。如果您正苦于以下问题:C++ SortedList类的具体用法?C++ SortedList怎么用?C++ SortedList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SortedList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_findmax
void test_findmax()
{
#if FINDMAX
printf("Running test_findmax\n");
SortedList l1, l2;
int m1, m2;
readFile(l1, file1);
readFile(l2, file2);
m1 = l1.findMax();
m2 = l2.findMax();
cout << "list is ";
l1.print();
printf("Your max is %d, should be 78\n", m1);
cout << "list is ";
l2.print();
printf("Your max is %d, should be 42\n", m2);
SortedList eric;
eric.insert(-100);
eric.insert(-101);
eric.insert(-102);
m1 = eric.findMax();
cout << "list is ";
eric.print();
printf("Your max is %d, should be -100\n", m1);
#endif
}
示例2: GetBounds
Rect GuiTableComposition::GetBounds()
{
Rect cached = previousBounds;
Rect result = GuiBoundsComposition::GetBounds();
bool cellMinSizeModified = false;
SortedList<GuiCellComposition*> cells;
FOREACH(GuiCellComposition*, cell, cellCompositions)
{
if (cell && !cells.Contains(cell))
{
cells.Add(cell);
Size newSize = cell->GetPreferredBounds().GetSize();
if (cell->lastPreferredSize != newSize)
{
cell->lastPreferredSize = newSize;
cellMinSizeModified = true;
}
}
}
if (cached != result || cellMinSizeModified)
{
UpdateCellBounds();
}
return result;
}
示例3:
QuadTree::QuadTree( SortedList& source )
{
//Create the first node in the tree
nodeData next;
source.ResetList();
source.GetNextItem( next );
treeData = new treeNode;
treeData -> tagged = false;
treeData -> NW = NULL;
treeData -> SW = NULL;
treeData -> SE = NULL;
treeData -> NE = NULL;
currentPos = treeData;
(currentPos->point).x = (next.centroid).x;
(currentPos->point).y = (next.centroid).y;
length = 1;
//Iterate through the sorted list and insert items into tree
while ( !source.IsLastItem() )
{
source.GetNextItem( next );
insert( treeData, next.centroid );
}
}
示例4: CollectTypeDescriptors
static void CollectTypeDescriptors(ITypeDescriptor* td, SortedList<ITypeDescriptor*>& tds)
{
if (!tds.Contains(td))
{
tds.Add(td);
}
}
示例5: checkfreq
void checkfreq(SortedList& l, int num, int correct)
{
printf("Running checkfreq\n");
int f = l.freq(num);;
cout << "list is ";
l.print();
printf("Your freq(%d) rets %d, should be %d\n", num, f, correct);
#endif
}
示例6:
void SortedList<T, Pred>::copyNodes(const SortedList<T, Pred>& rhs)
{
SortedList<T, Pred>::const_iterator iter = rhs.begin();
while (iter != rhs.end())
{
push_back(*iter);
++iter;
}
}
示例7: checkwhereis
void checkwhereis(SortedList& l, int num, string correct)
{
SortedList result;
result = l.whereis(num);
cout << "whereis "<< num << " in " ;
l.print();
confirm("your result", result, correct);
#endif
}
示例8: buildHuffTree
void RosettaCodeProvider::buildHuffTree()
{
//build Node list from HuffCodeTable, no need to sort (already done on get call)
SortedList<HuffNode*> nodeList;
int i = 0;
HuffData* iterate = _huffCodeTable->get(i);
while(iterate != nullptr){
++i;
nodeList.addWithoutSort(new HuffNode(iterate));
iterate = _huffCodeTable->get(i);
}
//merge nodes together
while(nodeList.size() >= 2){
HuffNode* one = nodeList.remove(0);
HuffNode* two = nodeList.remove(0);
unsigned sum = one->getFrequency() + two->getFrequency();
HuffNode* three = new HuffNode(sum);
if(*one < *two){
three->_leftChild = one;
three->_rightChild = two;
}else{
three->_leftChild = two;
three->_rightChild = one;
}
nodeList.addWithSort(three);
}
if(nodeList.size() == 0){
//something went wrong
//nothing in codeTable to start with?
return;
}
if(nodeList.size() == 1){
_huffTree = new HuffTree(nodeList.remove(0));
}
}
示例9: SearchLeafClasses
void SearchLeafClasses(List<ParsingSymbol*>& classes, List<ParsingSymbol*>& leafClasses)
{
SortedList<ParsingSymbol*> parents;
CopyFrom(
parents,
From(classes)
.Select([](ParsingSymbol* type){ return type->GetDescriptorSymbol(); })
.Distinct()
);
CopyFrom(
leafClasses,
From(classes)
.Where([&parents](ParsingSymbol* type){ return !parents.Contains(type); })
);
}
示例10: confirm
//
// Show user what the list contains then show what it ought to contain
// Let the user decide if it is correct
//
void confirm(string name, SortedList& l, string correct)
{
cout << name << " is now:" << endl;
l.print();
cout << "It should be" << endl;
cout << correct << endl << endl;
}
示例11: Essai1
void Essai1()
{
cout << "----- 1. Test du template ListeTriee avec des entiers ------------------------" << endl;
cout << "Creation d'une Liste triee..." << endl;
SortedList<int> liste;
liste.display(); // --> ()
cout << endl;
cout << "On insere 3,-2,5,-1,0 et -8..." << endl;
liste.add(3);
liste.add(-2);
liste.add(5);
liste.add(-1);
liste.add(0);
liste.add(-8);
liste.display(); // --> (-8 -2 -1 0 3 5)
cout << "La liste contient " << liste.size() << " elements." << endl;
cout << endl;
}
示例12: g
LLDependenciesBase::VertexList LLDependenciesBase::topo_sort(int vertices, const EdgeList& edges) const
{
// Construct a Boost Graph Library graph according to the constraints
// we've collected. It seems as though we ought to be able to capture
// the uniqueness of vertex keys using a setS of vertices with a
// string property -- but I don't yet understand adjacency_list well
// enough to get there. All the examples I've seen so far use integers
// for vertices.
// Define the Graph type. Use a vector for vertices so we can use the
// default topological_sort vertex lookup by int index. Use a set for
// edges because the same dependency may be stated twice: Node "a" may
// specify that it must precede "b", while "b" may also state that it
// must follow "a".
typedef boost::adjacency_list<boost::setS, boost::vecS, boost::directedS,
boost::no_property> Graph;
// Instantiate the graph. Without vertex properties, we need say no
// more about vertices than the total number.
Graph g(edges.begin(), edges.end(), vertices);
// topo sort
typedef boost::graph_traits<Graph>::vertex_descriptor VertexDesc;
typedef std::vector<VertexDesc> SortedList;
SortedList sorted;
// note that it throws not_a_dag if it finds a cycle
try
{
boost::topological_sort(g, std::back_inserter(sorted));
}
catch (const boost::not_a_dag& e)
{
// translate to the exception we define
std::ostringstream out;
out << "LLDependencies cycle: " << e.what() << '\n';
// Omit independent nodes: display only those that might contribute to
// the cycle.
describe(out, false);
throw Cycle(out.str());
}
// A peculiarity of boost::topological_sort() is that it emits results in
// REVERSE topological order: to get the result you want, you must
// traverse the SortedList using reverse iterators.
return VertexList(sorted.rbegin(), sorted.rend());
}
示例13: readFile
void readFile(SortedList &l, const char filename[])
{
int temp;
ifstream fin;
fin.open(filename);
while ( fin >> temp ) {
l.insert(temp);
}
fin.close();
}
示例14: main
int main()
{
SortedList* sl = new SortedList();
sl->insert(1);
sl->insert(50);
sl->displayList();
sl->insert(3);
sl->insert(20);
sl->insert(7);
sl->displayList();
while(sl->removeFirst())
sl->displayList();
delete sl;
return 0;
} // end main()
示例15: main
int main()
{
int j;
time_t aTime; // seed random numbers
srand(static_cast<unsigned>(time(&aTime)));
const int size = 10;
Link* linkArray[size]; // array of ptrs to links
for(j = 0; j < size; j++) // fill with ptrs to links
{
int n = rand() % 99; // random number (0 to 99)
Link* pNewLink = new Link(n);
linkArray[j] = pNewLink;
}
cout << "Unsorted array: ";
for(j = 0; j < size; j++)
linkArray[j]->displayLink();
cout << endl;
SortedList *sl = new SortedList(linkArray, size);
for(j = 0; j < size; j++)
linkArray[j] = sl->removeFirst();
cout << "Sorted Array: ";
for(j = 0; j < size; j++)
linkArray[j]->displayLink();
cout << endl;
for(j = 0; j < size; j++) // delete indivisual links
delete linkArray[j];
return 0;
} // end main()