本文整理汇总了C++中sizeDynArr函数的典型用法代码示例。如果您正苦于以下问题:C++ sizeDynArr函数的具体用法?C++ sizeDynArr怎么用?C++ sizeDynArr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sizeDynArr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: removeMinHeap
/* Remove the first node, which has the min priority, from the heap
param: heap pointer to the heap
pre: heap is not empty
post: the first node is removed from the heap
*/
void removeMinHeap(DynArr *heap)
{
/* heap->data should be replaced with getmin function*/
heap->data[0] = getDynArr(heap, (sizeDynArr(heap) - 1));
heap->size--;
_adjustHeap(heap, (sizeDynArr(heap) - 1), 0);
}
开发者ID:Mankee,项目名称:CS261,代码行数:13,代码来源:dynArray.c
示例2: removeMinHeap
/* Remove the first node, which has the min priority, from the heap
*
* param: heap pointer to the heap
* pre: heap is not empty
* post: the first node is removed from the heap
* */
void removeMinHeap(DynArr *heap)
{
/* FIXME */
heap->data[0] = getDynArr(heap, (sizeDynArr(heap) - 1));
heap->size--;
_adjustHeap(heap, (sizeDynArr(heap) - 1), 0);
}
开发者ID:avisinha1,项目名称:CS-261,代码行数:13,代码来源:dynArray.c
示例3: _smallerIndexHeap
/* Get the index of the smaller node between two nodes in a heap
param: heap pointer to the heap
param: i index of one node
param: j index of other node
pre: i < size and j < size
ret: the index of the smaller node
*/
int _smallerIndexHeap(DynArr *heap, int i, int j)
{
assert(i < sizeDynArr(heap));
assert(j < sizeDynArr(heap));
if (compare(getDynArr(heap, i), getDynArr(heap, j)) == -1)
return i;
else
return j;
}
开发者ID:Mankee,项目名称:CS261,代码行数:17,代码来源:dynArray.c
示例4: _buildHeap
void _buildHeap(DynArr *heap)
{
assert( heap != NULL );
assert( sizeDynArr( heap ) > 0 );
/* Start at the last non-leaf node */
for( int i = ( sizeDynArr( heap ) / 2 ) - 1; i >= 0; --i )
{
_adjustHeap( heap, sizeDynArr( heap ), i );
}
}
开发者ID:jonese8,项目名称:cs261,代码行数:11,代码来源:dynamicArray.c
示例5: character
/* Save the list to a file
param: heap pointer to the list
param: filePtr pointer to the file to which the list is saved
pre: The list is not empty
post: The list is saved to the file in tab-delimited format.
Each line in the file stores a task, starting with the
task priority, followed by a tab character (\t), and
the task description.
The tasks are not necessarily stored in the file in
priority order.
*/
void saveList(DynArr *heap, FILE *filePtr)
{
int i;
Task* task;
assert(sizeDynArr(heap) > 0);
for(i = 0; i < sizeDynArr(heap); i++)
{
task = getDynArr(heap, i);
fprintf(filePtr, "%d\t%s\n", task->priority, task->description);
}
}
开发者ID:lalocalindsay,项目名称:sampleProjects,代码行数:25,代码来源:toDoList.c
示例6: removeDynArr
/* Removes the first occurrence of the specified value from the collection
if it occurs
param: v pointer to the dynamic array
param: val the value to remove from the array
pre: v is not null
pre: v is not empty
post: val has been removed
post: size of the bag is reduced by 1
*/
void removeDynArr(DynArr *v, TYPE val)
{
/* FIXME: You will write this function */
int i;
for (i = 0; i < sizeDynArr(v); i++) {
/* If the value is found we will remove it and end the for loop */
if(EQ(val, v->data[i])) {
removeAtDynArr(v, i);
i = sizeDynArr(v) + 1;
}
}
}
开发者ID:mustang25,项目名称:CS261,代码行数:22,代码来源:dynamicArray.c
示例7: _smallerIndexHeap
/* Get the index of the smaller node between two nodes in a heap
param: heap pointer to the heap
param: i index of one node
param: j index of other node
pre: i < size and j < size
ret: the index of the smaller node
*/
int _smallerIndexHeap(DynArr *heap, int i, int j)
{
assert(i < sizeDynArr(heap));
assert(j < sizeDynArr(heap));
if(compare(heap->data[i], heap->data[j]) == -1) {
return i;
}
else {
return j;
}
}
开发者ID:quinnsam,项目名称:Oregon_State_Classes,代码行数:20,代码来源:dynamicArray.c
示例8: printList
/* Print the list
param: heap pointer to the list
pre: the list is not empty
post: The tasks from the list are printed out in priority order.
The tasks are not removed from the list.
*/
void printList(DynArr *heap)
{
/* FIXME: Write this */
struct DynArr *toPrint = createDynArr(sizeDynArr(heap));
copyDynArr(heap, toPrint);
int i, max = sizeDynArr(toPrint);
sortHeap(toPrint);
// call print_type() on each node
for(i = 0; i < max; i++)
print_type(getDynArr(toPrint, i));
deleteList(toPrint);
}
开发者ID:TatyanaV,项目名称:Data-Structures-C-,代码行数:19,代码来源:toDoList.c
示例9: printListHelper
/* Print the list
param: heap pointer to the list
pre: the list is not empty
post: The tasks from the list are printed out in priority order.
The tasks are not removed from the list.
*/
void printListHelper(DynArr *heap, int pos, int count){
printf("%d\t%s\n", heap->data[pos].priority, heap->data[pos].description);
count++;
while(count < sizeDynArr(heap)){
if((pos*2)+1 < sizeDynArr(heap))
printListHelper(heap, ((pos*2)+1), count);
if((pos*2)+2 <sizeDynArr(heap))
printListHelper(heap, ((pos*2)+2), count);
}
}
开发者ID:Nanaanim27,项目名称:OSU_Class_Projects,代码行数:20,代码来源:toDoList.c
示例10: sortHeap
void sortHeap(DynArr *heap)
{
assert( heap != NULL );
assert( sizeDynArr( heap ) > 0 );
_buildHeap( heap );
for( int i = ( sizeDynArr( heap ) - 1 ); i > 0; --i )
{
/* Swap the outer two elements in the heap, then adjust it */
swapDynArr( heap, i, 0 );
_adjustHeap( heap, i, 0 );
}
}
开发者ID:jonese8,项目名称:cs261,代码行数:13,代码来源:dynamicArray.c
示例11: divide
/* param: stack the stack being manipulated
pre: the stack contains at least two elements
post: the top two elements are popped and
their quotient is pushed back onto the stack.
*/
void divide(struct DynArr *stack){
if (sizeDynArr(stack) < 2){
printf( "\n ERROR \n");
printf("You need to have at least 2 numbers for division\n");
printf("Please use: number1 number2 / format \n");
printf("number1 / number2 will not work \n");
}
assert(sizeDynArr(stack) >= 2);
double number = topDynArr(stack);
popDynArr(stack);
double divide = topDynArr(stack)/number;
popDynArr(stack);
pushDynArr(stack, divide);
}
开发者ID:TatyanaV,项目名称:Data-Structures-C-,代码行数:19,代码来源:calc.c
示例12: subtract
/* param: stack the stack being manipulated
pre: the stack contains at least two elements
post: the top two elements are popped and
their difference is pushed back onto the stack.
*/
void subtract(struct DynArr *stack){
if (sizeDynArr(stack) < 2){
printf( "\n ERROR \n");
printf("You need to have at least 2 numbers for subtraction \n");
printf("Please use: number1 number2 - format \n");
printf("number1 - number2 will not work \n");
}
assert(sizeDynArr(stack) >= 2);
double number = topDynArr(stack);
popDynArr(stack);
double subtract = topDynArr(stack) - number;
popDynArr(stack);
pushDynArr(stack, subtract);
}
开发者ID:TatyanaV,项目名称:Data-Structures-C-,代码行数:19,代码来源:calc.c
示例13: add
/* param: stack the stack being manipulated
pre: the stack contains at least two elements
post: the top two elements are popped and
their sum is pushed back onto the stack.
*/
void add (struct DynArr *stack){
if (sizeDynArr(stack) < 2){
printf( "\n ERROR \n");
printf("You need to have at least 2 numbers for addition \n");
printf("Please use: number1 number2 + format \n");
printf("number1 + number2 will not work \n");
}
assert(sizeDynArr(stack) >= 2);
double first = topDynArr(stack);
popDynArr(stack);
double second = topDynArr(stack);
popDynArr(stack);
pushDynArr(stack, first + second);
}
开发者ID:TatyanaV,项目名称:Data-Structures-C-,代码行数:19,代码来源:calc.c
示例14: multiply
/* param: stack the stack being manipulated
pre: the stack contains at least two elements
post: the top two elements are popped and
their quotient is pushed back onto the stack.
*/
void multiply(struct DynArr *stack){
if (sizeDynArr(stack) < 2){
printf( "\n ERROR \n");
printf("You need to have at least 2 numbers for multiplication \n");
printf("Please use: number1 number2 x format \n");
printf("number1 x number2 will not work \n");
}
assert(sizeDynArr(stack) >= 2);
double num2 = topDynArr(stack);
popDynArr(stack);
double num1 = topDynArr(stack);
popDynArr(stack);
pushDynArr(stack, num1 * num2);
}
开发者ID:TatyanaV,项目名称:Data-Structures-C-,代码行数:19,代码来源:calc.c
示例15: _buildHeap
void _buildHeap(DynArr *heap)
{
/* FIXME */
assert(heap->size != 0);
int size = sizeDynArr(heap); //number of elements in heap
int subTree = size / 2 - 1; //1st non-leaf subtree
int max = sizeDynArr(heap); //last element in heap
while(subTree != 0)
{
_adjustHeap(heap, max, subTree); //percolate down the subtree and adjust order
subTree--; //find next subtree starting
}
}
开发者ID:eslamif,项目名称:data-structures-proj-5,代码行数:14,代码来源:dynamicArray.c
示例16: removeMinHeap
/* Remove the first node, which has the min priority, from the heap
param: heap pointer to the heap
pre: heap is not empty
post: the first node is removed from the heap
*/
void removeMinHeap(DynArr *heap)
{
int last;
assert( sizeDynArr( heap ) > 0 );
last = sizeDynArr( heap ) - 1;
/* Copy the last element to the first */
putDynArr( heap, 0, getDynArr( heap, last ) );
/* Remove last element */
removeAtDynArr( heap, last );
/* Rebuild heap */
_adjustHeap( heap, last, 0 );
}
开发者ID:jonese8,项目名称:cs261,代码行数:21,代码来源:dynamicArray.c
示例17: to
/* Adjust heap to maintain heap property
param: heap pointer to the heap
param: max index to adjust up to (but not included)
param: pos position index where the adjustment starts
pre: max <= size
post: heap property is maintained for nodes from index pos to index max-1 (ie. up to, but not including max)
*/
void _adjustHeap(DynArr *heap, int max, int pos)
{
/* FIXME */
int left, right, small;
assert(max <= sizeDynArr(heap));
left = 2 * pos +1;
right = 2 * pos +2;
if(right < max)
{
small = _smallerIndexHeap(heap, left, right);
if(compare(getDynArr(heap, small), getDynArr(heap, pos)) == -1)
{
swapDynArr(heap, pos, small);
_adjustHeap(heap, max, small);
}
}
else if(left < max)
{
if(compare(getDynArr(heap, left), getDynArr(heap, pos)) == -1)
{
swapDynArr(heap, pos, left);
_adjustHeap(heap, max, left);
}
}
}
开发者ID:bdcarter,项目名称:DataStructures,代码行数:41,代码来源:dynamicArray.c
示例18: to
/* Adjust heap to maintain heap property
param: heap pointer to the heap
param: max index to adjust up to (but not included)
param: pos position index where the adjustment starts
pre: max <= size
post: heap property is maintained for nodes from index pos to index max-1 (ie. up to, but not including max)
*/
void _adjustHeap(DynArr *heap, int max, int pos)
{
/* FIXME */
assert(max <= sizeDynArr(heap));
int left = (2 * pos) + 1;
int right = (2 * pos) + 2;
int small;
if(right < max)
{
small = _smallerIndexHeap(heap, left, right);
// can't alter type.h, but this would have been cleaner
// if(heap->data[small].priority < heap->data[pos].priority)
if (compare(getDynArr(heap,small),getDynArr(heap,pos)) == -1)
{
swapDynArr(heap, small, pos);
_adjustHeap(heap, max, small);
}
}
else if(left < max)
{
// here is the type.h problem again
// if(heap->data[left].priority < heap->data[pos].priority)
if (compare(getDynArr(heap,left),getDynArr(heap,pos)) == -1)
{
swapDynArr(heap, left, pos);
_adjustHeap(heap, max, left);
}
}
}
开发者ID:radiochickenwax,项目名称:mlib,代码行数:39,代码来源:dynamicArray.c
示例19: to
/* Adjust heap to maintain heap property
param: heap pointer to the heap
param: max index to adjust up to (but not included)
param: pos position index where the adjustment starts
pre: max <= size
post: heap property is maintained for nodes from index pos to index max-1 (ie. up to, but not including max)
*/
void _adjustHeap(DynArr *heap, int max, int pos)
{
assert(max <= sizeDynArr(heap));
int leftidx = (pos*2)+1;
int rightidx = (pos*2)+2;
int smallidx;
// TYPE temp;
if(rightidx < max) { //2 Children
smallidx = _smallerIndexHeap(heap, leftidx, rightidx);
if(compare(heap->data[smallidx], heap->data[pos]) == -1) {
/*temp = heap->data[smallidx];
heap->data[smallidx] = heap->data[pos];
heap->data[pos] = temp;*/
swapDynArr(heap, pos, smallidx);
_adjustHeap(heap, max, smallidx);
}
}
else if(leftidx < max) { // 1 Child
if(compare(heap->data[pos], heap->data[leftidx]) == -1) {
//heap->data[pos] = heap->data[leftidx];
swapDynArr(heap, pos, leftidx);
_adjustHeap(heap, max, leftidx);
}
}
}
开发者ID:quinnsam,项目名称:Oregon_State_Classes,代码行数:34,代码来源:dynamicArray.c
示例20: _buildHeap
void _buildHeap(DynArr *heap)
{
/* FIXME */
int index = sizeDynArr(heap);
for (int i = index / 2 - 1; i>=0; i--)
_adjustHeap(heap, index, i);
}
开发者ID:TatyanaV,项目名称:Data-Structures-C-,代码行数:7,代码来源:dynamicArray.c
注:本文中的sizeDynArr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论