TutPtrArySwapItems


Name

TutPtrArySwapItems — exchange the two specified elements in a pointer array

Synopsis

T_BOOL TutPtrArySwapItems(ptr_ary, index1, index2) 
T_PTR_ARY ptr_ary; 
T_INT4 index1; 
T_INT4 index2; 

Arguments

ptr_ary — pointer array to operate on

index1 — index of the first element

index2 — index of the second element

Return Values

TRUE if the operation is a success, FALSE otherwise.

Diagnostics

None

Description

TutPtrArySwapItems exchanges the two items at the specified indices. The function returns TRUE if the operation was successful and FALSE if invalid indices were specified.

TutPtrArySwapItems calls the pointer array change callbacks with the reason T_PA_ITEMS_SWAPPED.

Caution

None

See Also

TutPtrAryCreate, TutPtrArySort

Examples

This example swaps items in a pointer array:

T_PTR_ARY ptr_ary; 
T_INT4 i, *int_ptr; 
 
/* create the pointer array with initial size of 30 */ 
 
ptr_ary = TutPtrAryCreate(30); 
/* fill it up with 25 entries */ 
for (i = 0; i < 25; i++) { 
  /* allocate the space for the next element */ 
  T_MALLOC(int_ptr, sizeof(T_INT4), T_INT4 *); 
  *int_ptr = i; 
  /* append the item to the array, ignore the index */ 
  TutPtrAryAppend(ptr_ary, int_ptr, NULL); 
}  
/* swap items at indices 4 and 12 */ 
TutPtrArySwapItems(ptr_ary, 4, 12); 

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com