List.nth is 'T list - int - 'T, rather than the standard int - 'T list - 'T like Seq.nth.
This makes pipeline somewhat awkward.
Is there something behind the scene?
I don't know why.
I have 2 simple structures:
struct Address
{
char city[255];
};
typedef Address* AddressPtr;
struct Person
{
char fullName[255];
Address* address;
Person* next;
};
typedef Person* PersonPtr;
The Person structure forms the Linked list where new elements are added to the beginning of the list. What I want to do is to sort them by fullName. At first I tried to swap links, but I lost the beginning of the list and as a result my list was sorted partially. Then I decided to sort list by swapping the values of nodes. But I get strange results. For a list with names: Test3, Test2, Test1, I get Test3, Test3, Test3.
Here is my sorting code:
void sortByName(PersonPtr& head)
{
TaskPtr currentNode, nextNode;
for(currentNode = head; currentNode->next != NULL; currentNode = currentNode->next)
{
for(nextNode = currentNode->next; nextNode != NULL; nextNode = nextNode->next)
{
if(strcmp(currentNode->fullName, nextNode->fullName) > 0)
{
swapNodes(currentNode, nextNode);
}
}
}
}
void swapNodes(PersonPtr& node1, PersonPtr& node2)
{
PersonPtr temp_node = node2;
strcpy(node2->fullName, node1->fullName);
strcpy(node1->fullName, temp_node->fullName);
strcpy(node2->address->city, node1->address->city);
strcpy(node1->address->city, temp_node->address->city);
}
After the sorting completion, nodes values are a little bit strange.
UPDATED
This is how I swapped links
void swapNodes(PersonPtr& node1, PersonPtr& node2)
{
PersonPtr temp_person;
AddressPtr temp_address;
temp_person = node2;
node2 = node1;
node1 = temp_person;
temp_address = node2->address;
node2->address = node1->address;
node1->address = temp_address;
}
If I want a list initialized to 5 zeroes, that's very nice and easy:
[0] * 5
However if I change my code to put a more complicated data structure, like a list of zeroes:
[[0]] * 5
will not work as intended, since it'll be 10 copies of the same list. I have to do:
[[0] for i in xrange(5)]
that feels bulky and uses a variable so sometimes I even do:
[[0] for _ in " "]
But then if i want a list of lists of zeros it gets uglier:
[[[0] for _ in " "] for _ in " "]
all this instead of what I want to do:
[[[0]]*5]*5
Has anyone found an elegant way to deal with this "problem"?
i'm trying to get a list of the most recent used applications. NSWorkspace returns me a list of active applications and i can sort them on a few options using NSRunningApplication. see list below:
launchDate
finishedLaunching
processIdentifier
i dont want the lauch date but the recent 'active' date (like the way cmd-tab sorts).
Does anyone knows the solution for this?
I am making a shopping list app. When an item is added to the text input, it should be converted into a list item with a class of "tile" and added to the beginning of the list with a class of ".shopping_item_list". Here is my HTML:
<section>
<h1 class="outline">Shopping List Items</h1>
<ul class="shopping_item_list">
<li class="tile">Flowers<span class="delete">Delete</span></li>
</ul>
</section>
My jQuery:
$("input[name='shopping_item']").change(function() {
var item = $(this).val();
$("<li class='tile'>+ item +</li>").prependTo(".shopping_item_list");
$(".tile").removeClass("middle");
$(".shopping_item_list li:nth-child(3n+2)").addClass("middle");
});
This isn't working, and I can't figure out why. I'm new to jQuery.
Also, I need to add the "delete" span to the list item and am not sure how.
Thanks for any help you can offer!
Edited to add:
Thanks to the feedback here, I was able to make it work with:
$("input[name='shopping_item']").change(function() {
var item = $(this).val();
$("<li class='tile'>" + item + "<span class='delete'>Delete</span>" + " </li>").prependTo(".shopping_item_list");
$(".tile").removeClass("middle");
$(".shopping_item_list li:nth-child(3n+2)").addClass("middle");
});
However, in my jquery, I have functions for the classes "tile" and "delete" that are not working for newly added items.
// hide delete button
$(".delete").hide();
// delete square
$(".tile").hover(function() {
$(this).find(".delete").toggle();
});
$(".tile").on("click", ".delete", function() {
$(this).closest("li.tile").remove();
$(".tile").removeClass("middle");
$(".shopping_item_list li:nth-child(3n+2)").addClass("middle");
});
// cross off list
$(".tile").click(function() {
$(this).toggleClass("deleteAction");
});
The new items, which have these classes applied aren't using these functions at all. Do I need to add the functions below the add item? Does the order in which they appear in my js file matter? Do I need to add some kind of function?
I need to deploy a new List View for the standard List View Web Part in MOSS 2007 via the object model (the list already exists, a new view should be added). I need and want to make this list view read-only. This is because saving changes to the view would corrupt modifications made to Header/Footer.
How can I do that via the object model? I looked at the content db, the read-only flag (0x20) is stored with the view and could technically be updated using calls to proc_GetAllWebPartsOnPage and proc_UpdateView[Properties]. NOTE: The database interface and all mentioned stored procs are all documented by Microsoft.
Is there ANY way to do that via the object model, because I would strongly prefer that?
I am kind of new to web development. I am trying to create a drop down menu, something I have now is like:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
but this is not exactly what I want. I want to create a drop down list very similar to the one on Amazon.com (the dropdown list beside "Search"), shown in following pic. so whenever user click on the button, the list will be displayed in the button as text. Please feel free to give me any ideas.
Thank you,
I currently have two Model classes:
class Leaders: List<Leaders>
{
public string LeaderName { get; set; }
public string PrecintName { get; set; }
}
public class MarketReport
{
//A list of activists
public Leaders leaderlist { get; set; }
}
Now, I have no idea if I am doing the above correctly, but I want to populate the list within the MarketReport
foreach (var store in stores)
{
MarketReport.leaderlist.AddItem //I want to add an item of type Leader to the list
//so that I can pass it to MVC view
}
I have an application that requires we use distinct user connection strings per user. We are trying to upgrade from SubSonic 2.x to 3.0. I'm running into issues with trying to create a List< of objects. When I try to create a List like this:
List<table_name> oList = table_name.All().Where(tn => tn.table_id == TableId).ToList();
I get the error "Connection string 'ConnectionStringName' does not exist."
So, I try to create the List< like this:
List<table_name> oList = table_name.All(sConnectionString, "System.Data.SqlClient").Where(tn => tn.table_id == TableId).ToList();
I get the error "The name 'table_name' does not exist in the current context."
I'm using SQL Server, and the sConnectionString is definitely verified to be a good connection string, and the table_name is a table in the database. What am I doing wrong?
This should probably be pretty simple but my Google-Fu is as yet unable to find an answer. I simply want to create a dropdown list in Access so that upon selection I can perform some action based on the value of the selection. For instance, I have a list of people and I would like to populate the combo box so that their names appear in the list but the "value" is set to their ID (the primary key).
I'm creating a mobile website with jQuery, and I was wondering if there was a way to align a list to the bottom of a page, I just want the list to stay at the very bottom of the page, and be fixed in the spot. Thanks
This is the list im trying to get fixed on the bottom of the page:
<div data-role="content">
<div class="content-primary">
<ul data-role="listview">
<li><a href="link.html"><img src="file.jpg" /><h3>List name</h3></a>
</li>
</div>
On iOS, I am looking for the proper way to return the URLs for a list of files that are in a directory.
/images
1.jpg
2.jpg
3.jpg
...
I know the URL for the directory and know all the files in the directory will be of type jpeg. It is not clear to me how to properly format the NSURLRequest to return the list of files in the images directory. Once the list is returned, I will iterate through it to return the individual images.
Hi,
I have a sharepoint List.We will get the data from TEAMCENTER from there we will enter manually into the List.
Inorder to automatically update the sharepoint List with Teamcenter data is there any way????
The err part is Capitalized in the code, it also comes in foreaching. Because of the abstract list, it cannot be initialized, declaration is in a static field. The lists have the same type.
import java.util.*;
public class Test
{
public static final List<String> highPrio = Arrays.asList("*","/");
public static List<String> ops;
public static void main(String[] args)
{
//ERROR HERE, why do it throw nullPointer?
ops.addAll(highPrio);
for(String s : ops)
{
System.out.println(s);
}
}
}
I have a WCF WebService that uses LINQ and EF to connect to an SQL database. I have an ASP.NET MVC front end that collects its data from the webservice.
It currently has functions such as
List<Customer> GetCustomers();
As the number of customers increases massively the amount of data being passed increases also reducing efficiency. What is the best way to "page data" across WebServices etc.
My current idea is to implement a crude paging system such as
List<Customer> GetCustomers(int start, int length);
This, however, means I would have to replicate such code for all functions returning List types. It is unfortunate that I cannot use LINQ as it would be much nicer.
Does anyone have any advice or ideas of patterns to implement that would be "as nice as possible"
Thanks
Hi,
im using $this-widgetSchema-setFormFormatterName('list'); this way
below to render my form as a list but it is still a table. Any idea?
public function configure()
{
parent::configure();
$this->widgetSchema->setFormFormatterName('list');
}
}
Any idea?
Javi
I have a list of items sorted alphabetically:
list = [a,b,c,d,e,f,g,h,i,j]
I'm able to output the list in an html table horizonally like so:
| a , b , c , d |
| e , f , g , h |
| i , j , , |
What's the algorithm to create the table vertically like this:
| a , d , g , j |
| b , e , h , |
| c , f , i , |
I'm using python, but your answer can be in any language or even pseudocode.
Thanks
I need to walk a link list in the kernel debugger. How can I determine the head pointer and walk the list?
I have a listing and can find the address and location in the code where I check to see if I have a head, so I know the specific code location and address. But not sure how to determine the pointer or how to determine the next element and pointer on the list.
I need to let my users enter a variable length list of items into something that looks like a grid view (or a series of standard text boxes stacked vertically). Each item could be a few characters or a few hundred characters long, and I just want them to enter a "sentence", and then tab to the next row, and always having another blank one ready to go at the bottom of the list.
I don't want to save any data to my SQL Server DB until they enter the entire list and then click on a "save all" button.
When they hit the "save all" button they will be given a preview screen where the data will be presented as standard HTML ordered list.
If they confirm/save, then each row of the grid will then be saved as a separate row into my SQL Server database (with an index to remember the order).
What ASP.Net (or Jquery/javascript) UI control would be the best to use in this situation?
I have a IList. where the object PersonDetails consists of the persons name, address and phone number. The list consists of more than 1000 person details. I would like to display 50 PersonDetails per page. Is there a way to select only 50 elements from the list, and return them.
For example.
myList.select(1,50)
myList.select(51, 100)
I am able to select only first 50 by using. myList.Take(50);
The entire list is at the wcf service, and i would like to get only fifty elements at a time.
i have two lists:
List<comparerobj> list_c = new List<comparerobj>();
List<comparerobj> list_b = new List<comparerobj>();
i'm filling lists somehow
then i'm trying to find elements in list_b which list_c doesnt contain:
foreach (comparerobj b in list_b)
{
bool lc = !list_c.Contains(b);
if (lc != true)
{
data.Add(b);
}
}
but for any b i'm getting that lc = true. what am i doing wrong?
I switch in Xcode between working on a lot of different projects frequently (some I'm actively working on, some are old projects where I'm looking up code I want to re-use or quote in SO answers :)), so that part of my "working set" of projects invariably ends up falling off the recent project list. I do use finder tabs for the full working set of current project folders, but I really like the fast switching available using the recent projects list.
Is there a way to increase the length of this list so that I can see more recently opened projects?
I ran into following situation and I am wondering about best solution. Let's say I have List<Object1> and List<Object2>, these lists are result of two separated queries. Both of them have the same size and there is relationship 1:1 between elements in the lists based on ID. I know that best solution would be fetching data in one DB query but that's possible right now.
So my question is, what is the best way to join these lists into let's say List<Object3>?
I've got two List<Name>s:
public class Name
{
public string NameText {get;set;}
public Gender Gender { get; set; }
}
public class Gender
{
public decimal MaleFrequency { get; set; }
public decimal MaleCumulativeFrequency { get; set; }
public decimal FemaleCumulativeFrequency { get; set; }
public decimal FemaleFrequency { get; set; }
}
If the NameText property matches, I'd like to take the FemaleFrequency and FemaleCumulativeFrequency from the list of female Names and the MaleFrequency and MaleCumulativeFrequency values from the list of male Names and create one list of Names with all four properties populated.
What's the easiest way to go about this in C# using .Net 3.5?