insert_sorted


Description:

[ Version ( since = "2.4" ) ]
public void insert_sorted (owned G data, CompareDataFunc<G> func)

Inserts data into this using func to determine the new position.

Example: Insert sorted:

public static int main () {
Queue<string> queue = new Queue<string> ();
bool asc = true;
CompareDataFunc<string> cmpfunc = (a, b) => {
return (asc)? strcmp (a, b) : strcmp (b, a);
};

queue.insert_sorted ("2", cmpfunc);
queue.insert_sorted ("1", cmpfunc);
queue.insert_sorted ("3", cmpfunc);

// Output: ``1 2 3 ``
string item = null;
while ((item = queue.pop_head ()) != null) {
print ("%s ", item);
}
print ("\n");

return 0;
}

valac --pkg glib-2.0 GLib.Queue.insert_sorted.vala

Parameters:

this

a Queue

data

the data to insert

func

the CompareDataFunc used to compare elements in the queue. It is called with two elements of the this and user_data. It should return 0 if the elements are equal, a negative value if the first element comes before the second, and a positive value if the second element comes before the first.

user_data

user data passed to func