Search Results

Search found 36179 results on 1448 pages for 'generic list'.

Page 31/1448 | < Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >

  • Sort list using stl sort function

    - by Vlad
    I'm trying to sort a list (part of a class) in descending containg items of a struct but it doesn't compile(error: no match for 'operator-' in '__last - __first'): sort(Result.poly.begin(), Result.poly.end(), SortDescending()); And here's SortDescending: struct SortDescending { bool operator()(const term& t1, const term& t2) { return t2.pow < t1.pow; } }; Can anyone tell me what's wrong? Thanks!

    Read the article

  • Use of Distinct with list of Custom Object

    - by Burnzy
    How can I make the Distinct() method work with a list of custom object(Href in this case), here is what the current object looks like: public class Href : IComparable, IComparer<Href> { public Uri URL { get; set; } public UrlType URLType { get; set; } public Href(Uri url, UrlType urltype) { URL = url; URLType = urltype; } #region IComparable Members public int CompareTo( object obj ) { if(obj is Href) { return URL.ToString().CompareTo( ( obj as Href ).URL.ToString() ); } else throw new ArgumentException("Wrong data type."); } #endregion #region IComparer<Href> Members int IComparer<Href>.Compare( Href x , Href y ) { return string.Compare( x.URL.ToString() , y.URL.ToString() ); } #endregion }

    Read the article

  • Throw exception from initializer list

    - by aaa
    hello. what is the best way to throw exception from initializer list? for example: class C { T0 t0; // can be either valid or invalid, but does not throw directly T1 t1; // heavy object, do not construct if t0 is invalid, by throwing before C(int n) : t0(n), // throw exception if t0(n) is not valid t1() {} }; I thought maybe making wrapper, e.g. t0(throw_if_invalid(n)). What is the practice to handle such cases? Thanks

    Read the article

  • Algorithm to create a linked list from a set of nodes

    - by user320587
    Hi, I am looking for an algorithm to create a linked list from a set of nodes. For example, let's assume a node is an airline ticket from a source point to destination. (e.g., Chicago to Detroit) and there are several airline tickets. Assuming all these airline tickets are jumbled, what is the best way to determine the entire journey path. If there are 5 airline tickets like Chicago-Detroit, Denver-Chicago, Detroit-DC, DC-New York, San Jose-Denver, the algorithm should be able to come up with the correct start to end path. San Jose - Denver - Chicago - Detroit - DC - New York

    Read the article

  • Help with PHP recursive navigation list menu

    - by Jason
    Hi all, I am trying to add a dynamic recursive navigation list menu to a site of am working on. The scenerio is that the menu has 2 levels related by a parentid(preid). My issue is that I can display the 1st level list correctly, however I cannot get the second level to display properly. I am not sure where to add the UL and /UL tags for the second level. This is what I am after <ul> <li>Item 1</li> <li>item 2</li> <li>item 3</li> <ul> <li>sub item 1</li> <li>sub item 2</li> </ul> <li>Item 4</li> <li>item 5</li> <ul> <li>sub item 1</li> <li>sub item 2</li> </ul> <li>item 6</li> </ul> This is actually what i am getting with the below code: <ul> <li>item 1 <ul> </ul> </li> <li>item 2 <ul> <li>sub item 1</li> <ul> </ul> <li>sub item 2</li> <ul> </ul> </ul> </li> <li>Sports Injuries <ul> </ul> </li> </ul> </li> </ul> Below is the class file I am using to create the menu: class Dynamic_Menu { function getConfig() { $this->DB_SERVER = 'localhost'; $this->DB_USER = '***'; $this->DB_PASS = '***'; $this->DB_NAME = '***'; } function __construct() { $this->getConfig(); $Conn = mysql_connect($this->DB_SERVER, $this->DB_USER, $this->DB_PASS); if (!$Conn) die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn)); $DB_select = mysql_select_db($this->DB_NAME, $Conn); if (!$DB_select) die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn)); } function select_row($sql) { //echo $sql . "<br />"; if ($sql!="") { $result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error()); if ($result) { while($row = mysql_fetch_array($result)) $data[] = $row; } return $data; } } function recordCount($sql) { if ($sql!="") { $result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error()); if ($result) { $cnt = mysql_num_rows($result); return $cnt; } } } function getChild($id) { $menu = ""; $str = ""; $s = "SELECT * FROM vcms_sys_explorer WHERE preid = '$id' "; $res = $this->select_row($s); $menu .= '<ul>'; for ($i=0;$i<count($res);$i++) { $cnt_of_child = $this->recordCount("SELECT * FROM vcms_sys_explorer where preid = '".$res[$i][eid]."' "); //if ($cnt_of_child > 0) // $str = ''; //else // $str = " (is sub menu item)"; $menu .= '<li>'. $res[$i][name].$str.'</li>'; $menu .= $this->getChild($res[$i][eid]); } $menu .= '</ul>'; return $menu; } function getMenu($parentid) { $menu = ""; $s = "SELECT * FROM vcms_sys_explorer WHERE preid = '$parentid' "; $res = $this->select_row($s); $menu .= '<ul>'; for ($i=0;$i<count($res);$i++) { $menu .= '<li>'.$res[$i][name].$this->getChild($res[$i][eid]).'</li>'; if ((count($res) - 1) > $i) { } } $menu .= '</ul>'; return $menu; } } I call the menu with: $menu = new Dynamic_Menu(); $menu->getMenu(1); Could someone please help and explain where I need to place the level 2 UL and /UL tags. I have been banging my head with this for the last 2 days. Any help would be greatly appreciated, thanks...

    Read the article

  • Convert From Custom List to List of String

    - by Paul Johnson
    Hi all I have the following code: Public Shared Function ConvertToString(ByVal list As IList) As String Dim strBuilder = New System.Text.StringBuilder() Dim item As Object For Each item In list strBuilder.Append(obj.ToString()) strBuilder.Append(",") Next Return strBuilder.ToString(strBuilder.Length - 1) End Function The intention is to convert an IList of custom objects to a string equivalent comprising each element in the Ilist. Unfortunately I can't seem to find a way to get the underlying data of the custom object, and of course as in the above example, using object simply gives me a string of types definitions, rather than access to the underlying data. Any assistance much appreciated. Paul.

    Read the article

  • Generic collection as a Java method argument

    - by Guido
    Is there any way to make this work in Java? public static void change(List<? extends Object> list, int position1, int position2) { Object obj = list.get(position1); list.set(position1, list.get(position2)); list.set(position2, obj); } The only way I've successfully avoided warnings and errors is this: public static <T> T change(List<T> list, int position1, int position2) { T obj = list.get(position1); list.set(position1, list.get(position2)); list.set(position2, obj); return obj; } but I don't like to be forced to return a value.

    Read the article

  • transform List<XElement> to List<XElement.Value>

    - by Miau
    I have a result of a xlinq that is an enumerable with id and phones, I want to transform that to a Dictionary, that part is simple, however the part of transforming the phone numbers from a XElement to a string its proving hard xLinqQuery.ToDictionary(e => e.id, e => e.phones.ToList()); will return Dictionary<int, List<XElement>> what i want is a Dictionary<int, List<String>> I tried with e.phones.ToList().ForEach(...) some strange SelectMany, etc ot no avail Thanks

    Read the article

  • C++, throw exception from initializer list

    - by aaa
    hello. what is the best way to throw exception from initializer list? for example: class C { T0 t0; // can be either valid or invalid, but does not throw directly T1 t1; // heavy object, do not construct if t0 is invalid, by throwing before C(int n) : t0(n), // throw exception if t0(n) is not valid t1() {} }; I thought maybe making wrapper, e.g. t0(throw_if_invalid(n)). What is the practice to handle such cases? Thanks

    Read the article

  • Adjacency List Tree Using Recursive WITH (Postgres 8.4) instead of Nested Set

    - by Koobz
    I'm looking for a Django tree library and doing my best to avoid Nested Sets (they're a nightmare to maintain). The cons of the adjacency list model have always been an inability to fetch descendants without resorting to multiple queries. The WITH clause in Postgres seems like a solid solution to this problem. Has anyone seen any performance reports regarding WITH vs. Nested Set? I assume the Nested set will still be faster but as long as they're in the same complexity class, I could swallow a 2x performance discrepancy. Django-Treebeard interests me. Does anyone know if they've implemented the WITH clause when running under Postgres? Has anyone here made the switch away from Nested Sets in light of the WITH clause?

    Read the article

  • need to print 5 column list in alpha order, vertically

    - by Brad
    Have a webpage that will be viewed by mainly IE users, so CSS3 is out of the question. I want it to list like: A D G B E H C F I Here is the function that currently lists like: A B C D E F G H I function listPhoneExtensions($group,$group_title) { $adldap = new adLDAP(); $group_membership = $adldap->group_members(strtoupper($group),FALSE); sort($group_membership); print " <a name=\"".strtolower($group_title)."\"></a> <h2>".$group_title."</h2> <ul class=\"phone-extensions\">"; foreach ($group_membership as $i => $username) { $userinfo = $adldap->user_info($username, array("givenname","sn","telephonenumber")); $displayname = "<span class=\"name\">".substr($userinfo[0]["sn"][0],0,9).", ".substr($userinfo[0]["givenname"][0],0,9)."</span><span class=\"ext\">".$userinfo[0]["telephonenumber"][0]."</span>"; if($userinfo[0]["sn"][0] != "" && $userinfo[0]["givenname"][0] != "" && $userinfo[0]["telephonenumber"][0] != "") { print "<li>".$displayname."</li>"; } } print "</ul><p class=\"clear-both\"><a href=\"#top\" class=\"link-to-top\">&uarr; top</a></p>"; } Example rendered html: <ul class="phone-extensions"> <li><span class="name">Barry Bonds</span><span class="ext">8281</span></li> <li><span class="name">Gerald Clark</span><span class="ext">8211</span></li> <li><span class="name">Juan Dixon</span><span class="ext">8282</span></li> <li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li> <li><span class="name">Freddie Flank</span><span class="ext">2281</span></li> <li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li> <li><span class="name">Kim Moore</span><span class="ext">5767</span></li> <li><span class="name">Barry Bonds</span><span class="ext">8281</span></li> <li><span class="name">Gerald Clark</span><span class="ext">8211</span></li> <li><span class="name">Juan Dixon</span><span class="ext">8282</span></li> <li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li> <li><span class="name">Freddie Flank</span><span class="ext">2281</span></li> <li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li> <li><span class="name">Kim Moore</span><span class="ext">5767</span></li> <li><span class="name">Barry Bonds</span><span class="ext">8281</span></li> <li><span class="name">Gerald Clark</span><span class="ext">8211</span></li> <li><span class="name">Juan Dixon</span><span class="ext">8282</span></li> <li><span class="name">Omar Ebbs</span><span class="ext">8252</span></li> <li><span class="name">Freddie Flank</span><span class="ext">2281</span></li> <li><span class="name">Jerry Gilmore</span><span class="ext">4231</span></li> <li><span class="name">Kim Moore</span><span class="ext">5767</span></li> </ul> Any help is appreciated to getting it to list alpha vertically.

    Read the article

  • Java: Print and access List <String[]>

    - by battousai622
    Im reading in a file and storing it in t1. How do i access the elements in t1? When i try to print it i get addresses instead of values. Also whats the dif between string and string[]? CSVReader reader = new CSVReader(new FileReader("src/new_acquisitions.csv")); List <String[]> t1 = reader.readAll(); int i = 0 while(i < t1.size()) { System.out.println(t1.get(i)); i++; } output: [Ljava.lang.String;@9304b1 [Ljava.lang.String;@190d11 [Ljava.lang.String;@a90653 [Ljava.lang.String;@de6ced

    Read the article

  • pythonic way to associate list elements with their indices

    - by Dragan Chupacabrovic
    Hello Everybody, I have a list of values and I want to put them in a dictionary that would map each value to it's index. I can do it this way: >>> t = (5,6,7) >>> d = dict(zip(t, range(len(t)))) >>> d {5: 0, 6: 1, 7: 2} this is not bad, but I'm looking for something more elegant. I've come across the following, but it does the opposite of what I need: >>> d = dict(enumerate(t)) >>> d {0: 5, 1: 6, 2: 7} Please share your solutions, Thank you

    Read the article

  • Problem with list activity

    - by vikram deshpande
    I have implmented pagination and it display 5 records per page. Now suppose I am on page 3 and click 3'rd element then 3'rd element of page-1 is selected. I am not able to figure out problem as I always create new list object while setting data. I used below code temp = new ArrayList(); this.someListAdapter = new SomeListAdapter(this, R.layout.row_facet,temp); setListAdapter(this.someListAdapter ); Below is signature of SomeListAdapter class. public class SomeListAdapter extends ArrayAdapter<VoNeighborhood> { } Please help....

    Read the article

  • How do I copy only the values and not the references from a Python list?

    - by wrongusername
    Specifically, I want to create a backup of a list, then make some changes to that list, append all the changes to a third list, but then reset the first list with the backup before making further changes, etc, until I'm finished making changes and want to copy back all the content in the third list to the first one. Unfortunately, it seems that whenever I make changes to the first list in another function, the backup gets changed also. Using original = backup didn't work too well; nor did using def setEqual(restore, backup): restore = [] for number in backup: restore.append(number) solve my problem; even though I successfully restored the list from the backup, the backup nevertheless changed whenever I changed the original list. How would I go about solving this problem?

    Read the article

  • How to refactor these generic methods?

    - by Steve Crane
    I have written two nearly identical generic extension methods and am trying to figure out how I might refactor them into a single method. They differ only in that one operates on List and the other on List, and the properties I'm interested in are AssetID for AssetDocument and PersonID for PersonDocument. Although AssetDocument and PersonDocument have the same base class the properties are defined in each class so I don't think that helps. I have tried public static string ToCSVList<T>(this T list) where T : List<PersonDocument>, List<AssetDocument> thinking I might then be able to test the type and act accordingly but this results in the syntax error Type parameter 'T' inherits conflicting constraints These are the methods that I would like to refactor into a single method but perhaps I am simply going overboard and they would besat be left as they are. I'd like to hear what you think. public static string ToCSVList<T>(this T list) where T : List<AssetDocument> { var sb = new StringBuilder(list.Count * 36 + list.Count); string delimiter = String.Empty; foreach (var document in list) { sb.Append(delimiter + document.AssetID.ToString()); delimiter = ","; } return sb.ToString(); } public static string ToCSVList<T>(this T list) where T : List<PersonDocument> { var sb = new StringBuilder(list.Count * 36 + list.Count); string delimiter = String.Empty; foreach (var document in list) { sb.Append(delimiter + document.PersonID.ToString()); delimiter = ","; } return sb.ToString(); }

    Read the article

  • Adding Item to DataBound Drop Down List

    - by Stephen
    Yes, I have read most of the topics here, but I can't find an answer that works. I have Three drop-down lists. The first is databound to grab distinct experiment names. The user selects, page posts back, and the second drop-down menu displays distinct time points. This is where I need help. I need to add an item to THAT drop-down list whose ID, DataTextField, DataValueField are all TimePt. Seems simple, but I can't get it to work. protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { TimePt.DataSource = TimePTDD; TimePt.DataValueField = "TimePt"; TimePt.DataTextField = "TimePt"; TimePt.DataBind(); TimePt.Items.Insert(0, new ListItem("--Select---", "0")); TimePt.SelectedIndex = 0; } } I'm missing sometthing.

    Read the article

  • How to order a TimeZone list in .NET?

    - by reallyJim
    I have an ASP.NET web application that requires users to select their appropriate time zone so that it can correctly show local times for events. In creating a simple approach for selecting the time zone, I started by just using the values from TimeZoneInfo.GetSystemTimeZones(), and showing that list. The only problem with this is that since our application is primarily targeted at the United States, I'd like to show those entries first, basically starting with Eastern Time and working backwards (West) until I reach Atlantic time. What's a good approach to do this in code?

    Read the article

  • create a list of threads in C

    - by Hristo
    My implementation (in C) isn't working... the first node is always NULL so I can't free the memory. I'm doing: thread_node_t *thread_list_head = NULL; // done in the beginning of the program ... // later on in the program thread_node_t *thread = (thread_node_t*) malloc(sizeof(thread_node_t)); pthread_create(&(thread->thread), NULL, client_thread, &csFD); thread->next = thread_list_head; thread_list_head = thread; So when I try to free this memory, thread_list_head is NULL. while (thread_list_head != NULL) { thread_node_t *temp = thread_list_head; thread_list_head = thread_list_head->next; free(temp); temp = NULL; } Any advice on how to fix this or just a new way to create this list that would work better? Thanks, Hristo

    Read the article

  • adding a node to a linked list.

    - by sil3nt
    Hi there, ive been given the following code, And im just wondering, what does *&listpointer mean in the argument of the addnode function? struct Node { int accnumber; float balance; Node *next; }; Node *A, *B; int main() { A = NULL; B = NULL; AddNode(A, 123, 99.87); AddNode(B, 789, 52.64); } void AddNode(Node * & listpointer, int a, float b) { // add a new node to the FRONT of the list Node *temp; temp = new Node; temp->accnumber = a; temp->balance = b; temp->next = listpointer; listpointer = temp; }

    Read the article

  • Convert args to flat list?

    - by Mark
    I know this is very similar to a few other questions, but I can't quite get this function to work correctly. def flatten(*args): return list(item for iterable in args for item in iterable) The output I'm looking for is: flatten(1) -> [1] flatten(1,[2]) -> [1, 2] flatten([1,[2]]) -> [1, 2] The current function, which I from another SO answer doesn't seem to produce correct results at all: >>> flatten([1,[2]]) [1, [2]] I wrote the following function which seems to work for 0 or 1 levels of nesting, but not deeper: def flatten(*args): output = [] for arg in args: if hasattr(arg, '__iter__'): output += arg else: output += [arg] return output

    Read the article

  • TStringList, Dynamic Array or Linked List in Delphi?

    - by lkessler
    I have a choice. I have an array of ordered strings that I need to store and access. It looks like I can choose between using: A TStringList A Dynamic Array of strings, and A Linked List of strings In what circumstances is each of these better than the others? Which is best for small lists (under 10 items)? Which is best for large lists (over 1000 items)? Which is best for huge lists (over 1,000,000 items)? Which is best tor minimize memory use? Which is best to minimize loading and/or access time? For reference, I am using Delphi 2009.

    Read the article

  • Use LINQ and C# to make a new List from an old List

    - by Addie
    This should be pretty simple, but I am new at LINQ. I have a List of FillList structs. I'd like to use LINQ to create a new List where instead of having the number of buys and sells, I would have one variable containing the sum. For example, if the FillStruct structure has buy = 4 and sell = 2 then the NewFillStruct structure will have numlong = 2. If the FillStruct structure has buy = 2 and sell = 4 then the NewFillStruct structure will have numlong = -2. Here are the structures. struct FillStruct { int buy; int sell; string date; } struct NewFillStruct { int numlong; string date; }

    Read the article

  • Webapp: safetly update a shared List/Map in the AppContext

    - by al nik
    I've Lists and Maps in my WebAppContext. Most of the time these are only read by multiple Threads but sometimes there's the need to update or add some data. I'm wondering what's the best way to do this without incurring in a ConcurrentModificationException. I think that using CopyOnWriteArrayList I can achieve what I want in terms of - I do not have to sync on every read operation- I can safety update the list while other threads are reading it. Is this the best solution? What about Maps?

    Read the article

  • split a result list from mysql into separate lists based on list length

    - by liz
    i have a list of returned rows from mysql that i am outputting using php: echo '<ul class="mylist">'; foreach ($rows as $row) { echo '<li><a href="'.$row->url.'" target="_blank">' . $row->title . '</a></li>'; } echo "</ul>"; works fine, but its a long list and i would like to split it into ul chunks so that i can make columns. maybe like 5 results per ul. instead of one ul... i tried wrapping in a for statement but then just wound up outputting the results 5 times...oops...

    Read the article

< Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >