Search Results

Search found 5070 results on 203 pages for 'algorithm'.

Page 97/203 | < Previous Page | 93 94 95 96 97 98 99 100 101 102 103 104  | Next Page >

  • Pointer mysteriously moves

    - by Armen Ablak
    Hi, I have this code for Node rotation and in a line which is marked something happens and I don't really know what and why :). //Test case 30 \ 16 / 29 RotationRight(node->mParent); //call template<class T> void SplayTree<T>::RotationRight(SplayNode<T> *&node) const { SplayNode<T> *left = node->mLeft; SplayNode<T> *parent = node->mParent; node->mLeft = left->mRight; if(left->HasRight()) left->mRight->mParent = node; left->mRight = node; //node in this line points to 0x00445198 {30} left->mParent = node->mParent; //and in this line it points to 0x00444fb8 {16} (node, not node->mParent) node->mParent = left; node = left; } Well, left-mParent points to node also, so I basically do node = node-mParent. The problem is I can't find a work around - how to unpin in from node and change it's pointing address without changing it's.

    Read the article

  • Intersection() and Except() is too slow with large collections of custom objects

    - by Theo
    I am importing data from another database. My process is importing data from a remote DB into a List<DataModel> named remoteData and also importing data from the local DB into a List<DataModel> named localData. I am then using LINQ to create a list of records that are different so that I can update the local DB to match the data pulled from remote DB. Like this: var outdatedData = this.localData.Intersect(this.remoteData, new OutdatedDataComparer()).ToList(); I am then using LINQ to create a list of records that no longer exist in remoteData, but do exist in localData, so that I delete them from local database. Like this: var oldData = this.localData.Except(this.remoteData, new MatchingDataComparer()).ToList(); I am then using LINQ to do the opposite of the above to add the new data to the local database. Like this: var newData = this.remoteData.Except(this.localData, new MatchingDataComparer()).ToList(); Each collection imports about 70k records, and each of the 3 LINQ operation take between 5 - 10 minutes to complete. How can I make this faster? Here is the object the collections are using: internal class DataModel { public string Key1{ get; set; } public string Key2{ get; set; } public string Value1{ get; set; } public string Value2{ get; set; } public byte? Value3{ get; set; } } The comparer used to check for outdated records: class OutdatedDataComparer : IEqualityComparer<DataModel> { public bool Equals(DataModel x, DataModel y) { var e = string.Equals(x.Key1, y.Key1) && string.Equals(x.Key2, y.Key2) && ( !string.Equals(x.Value1, y.Value1) || !string.Equals(x.Value2, y.Value2) || x.Value3 != y.Value3 ); return e; } public int GetHashCode(DataModel obj) { return 0; } } The comparer used to find old and new records: internal class MatchingDataComparer : IEqualityComparer<DataModel> { public bool Equals(DataModel x, DataModel y) { return string.Equals(x.Key1, y.Key1) && string.Equals(x.Key2, y.Key2); } public int GetHashCode(DataModel obj) { return 0; } }

    Read the article

  • question about heapsearch order

    - by davit-datuashvili
    ia have meet following problem suppose we have sorted array of size 2^k-1 where k is given number we should copy this array into heapsearch array b the elements in odd positions of a go in order into last half of the positions of b positions congruent to 2 modul0 4 go into b's secodn quarter and so on this is not homework and please nobody tag it as homework it is from programming pearls please any ideas

    Read the article

  • Multiple "If...then....else if...." problem ?

    - by bahamut100
    Hi, I'm new in ASP development. This is my source code : ident = request.Form("ident") pass=request.Form("passe") response.write(ident) response.write(pass) if pass= "m" and ident="m" Then Session("connect")="membre" response.redirect("../") else if pass= "g" and ident="g" Then Session("connect")="gest" response.redirect("../") else if pass= "a" and ident="a" Then Session("connect")="admin" response.redirect("../") else response.redirect("ident.asp") End If But, with this code, I get this : "Erreur de compilation Microsoft VBScript error '800a0401' Fin d'instruction attendue /iisHelp/common/500-100.asp, line 11 Dim objASPError, blnErrorWritten, strServername, strServerIP, strRemoteIP Dim strMethod, lngPos, datNow, strQueryString, strURL --------------------------------------------------------------------------^ Erreur de compilation Microsoft VBScript error '800a03f6' 'End' attendu /groupe2/stage23/TP3/verif_id.asp, line 18 "

    Read the article

  • Triangulation in 3D Space

    - by w3b_wizzard
    Disclaimer: This is for class, however I'm fresh out of ideas and a nudge in the right direction would be much appreciated. Also, this needs to be implemented in raw C, so no fancy libraries can be used. I have to write a search and rescue simulator for submarines, it has to find a probe that is randomly placed in 3D space in a grid from of the MAX_XYZ (100000). The only tools I'm given are a "ping" which will give the magnitude of the distance between a certain sub and the probe. The goal is to optimize the costs of this entire operation so a brute force attempt, like looking at every single coordinate, won't work. Hence I was thinking triangulation. Now, it makes loads of sense to me, place three subs, each one of them uses their ping to get the distance between them and the probe. Since each sub have a known distance relative to one another, it's easy to build the base of a tetrahedron with them, and the results of the ping will point to a certain coordinate, the problem I'm having is how to figure out the elevation, or the height, of the tetrahedron. So what I have as data is the following: Distances between subs (In vector format) Angles between each subs (very easy to compute) Distance between each sub and the probe (3 segments from the base to the peak) Angles inside each of the outer 3 surfaces of the tetrahedron. I tried finding some sort of relationship with the vertices of the tetrahedron and the relative angles in each of them, however all I found had to deal with tetrahedrons built with equilateral triangles, which isn't much help. I have the impression this can be easily solved with trig but either I'm not seeing it or I need more coffee. Any suggestions would be appreciated!

    Read the article

  • How to convert from base-256 to base-N, where N is higher than 16?

    - by mark
    Dear ladies and sirs. I need to convert an array of bytes to another base, namely 85. In math terms the question is how to convert from base-256 to base-85 in the most efficient way? This question is inspired by my previous question - http://stackoverflow.com/questions/2827627/what-is-the-most-efficient-way-to-encode-an-arbitrary-guid-into-readable-ascii-3 Thanks.

    Read the article

  • bidirectional buble sort

    - by davit-datuashvili
    Here is the code I'm using for shacker sort (or bidirectional buble sort). Something is wrong; the error is java.lang.ArrayIndexOutOfBoundsException. Can anybody help me? public class bidirectional{ public static void main(String[]args){ int x[]=new int[]{12,9,4,99,120,1,3,10}; int j; int n=x.length; int st=-1; while (st<n){ st++; n--; for (j=st;j<n;j++) { if (x[j]>x[j+1]) { int t=x[j]; x[j]=x[j+1]; x[j+1]=t; } } for (j=n;--j>=st;) { if (x[j]>x[j+1]) { int t=x[j]; x[j]=x[j+1]; x[j+1]=t; } } } for (int k=0;k<x.length;k++) { System.out.println(x[k]); } } }

    Read the article

  • Shortest distance between points on a toroidally wrapped (x- and y- wrapping) map?

    - by mstksg
    I have a toroidal-ish Euclidean-ish map. That is the surface is a flat, Euclidean rectangle, but when a point moves to the right boundary, it will appear at the left boundary (at the same y value), given by x_new = x_old % width Basically, points are plotted based on: (x_new, y_new) = ( x_old % width, y_old % height) Think Pac Man -- walking off one edge of the screen will make you appear on the opposite edge. What's the best way to calculate the shortest distance between two points? The typical implementation suggests a large distance for points on opposite corners of the map, when in reality, the real wrapped distance is very close. The best way I can think of is calculating Classical Delta X and Wrapped Delta X, and Classical Delta Y and Wrapped Delta Y, and using the lower of each pair in the Sqrt(x^2+y^2) distance formula. But that would involve many checks, calculations, operations -- some that I feel might be unnecessary. Is there a better way?

    Read the article

  • java random percentages

    - by erw
    I need to generate n percentages (integers between 0 and 100) such that the sum of all n numbers adds up to 100. If I just do nextInt() n times, each time ensuring that the parameter is 100 minus the previously accumulated sum, then my percentages are biased (i.e. the first generated number will usually be largest etc.). How do I do this in an unbiased way?

    Read the article

  • question about partition

    - by davit-datuashvili
    i have question about hoare partition method here is code and also pseudo code please if something is wrong correct pseudo code HOARE-PARTITION ( A, p, r) 1 x ? A[ p] 2 i ? p-1 3 j ? r +1 4 while TRUE 5 do repeat j ? j - 1 6 until A[ j ] = x 7 do repeat i ? i + 1 8 until A[i] = x 9 if i < j 10 then exchange A[i] ? A[ j ] 11 else return j and my code public class Hoare { public static int partition(int a[],int p,int r) { int x=a[p]; int i=p-1; int j=r+1; while (true) { do { j=j-1; } while(a[j]>=x); do { i=i+1; } while(a[i]<=x); if (i<j) { int t=a[i]; a[i]=a[j]; a[j]=t; } else { return j; } } } public static void main(String[]args){ int a[]=new int[]{13,19,9,5,12,8,7,4,11,2,6,21}; partition(a,0,a.length-1); } } and mistake is this error: Class names, 'Hoare', are only accepted if annotation processing is explicitly requested 1 error any ideas

    Read the article

  • finding middle element of an array

    - by senthil
    Hi all, I came cross a question in my interview. Question: Array of integers will be given as the input and you should find out the middle element when sorted , but without sorting. For Example. Input: 1,3,5,4,2 Output: 3 When you sort the given input array, it will be 1,2,3,4,5 where middle element is 3. You should find this in one pass without sorting. Any solutions for this?

    Read the article

  • Python threading question (Working with a method that blocks forever)

    - by Nix
    I am trying to wrap a thread around some receiving logic in python. Basically we have an app, that will have a thread in the background polling for messages, the problem I ran into is that piece that actually pulls the messages waits forever for a message. Making it impossible to terminate... I ended up wrapping the pull in another thread, but I wanted to make sure there wasn't a better way to do it. Original code: class Manager: def __init__(self): receiver = MessageReceiver() receiver.start() #do other stuff... class MessageReceiver(Thread): receiver = Receiver() def __init__(self): Thread.__init__(self) def run(self): #stop is a flag that i use to stop the thread... while(not stopped ): #can never stop because pull below blocks message = receiver.pull() print "Message" + message What I refectored to: class Manager: def __init__(self): receiver = MessageReceiver() receiver.start() class MessageReceiver(Thread): receiver = Receiver() def __init__(self): Thread.__init__(self) def run(self): pullThread = PullThread(self.receiver) pullThread.start() #stop is a flag that i use to stop the thread... while(not stopped and pullThread.last_message ==None): pass message = pullThread.last_message print "Message" + message class PullThread(Thread): last_message = None def __init__(self, receiver): Thread.__init(self, target=get_message, args=(receiver)) def get_message(self, receiver): self.last_message = None self.last_message = receiver.pull() return self.last_message I know the obvious locking issues exist, but is this the appropriate way to control a receive thread that waits forever for a message? One thing I did notice was this thing eats 100% cpu while waiting for a message... **If you need to see the stopping logic please let me know and I will post.

    Read the article

  • Generate a valid array key from an URL string in PHP

    - by John Riche
    I have a PHP array with some predefined values: $aArray = array( 0 => 'value0', 1 => 'value1' ); I need to create a function where the string input will always return the same, valid, array key so that when I call: GiveMeAKey('http://www.google.com'); // May return 0 or 1 I receive always the same key (I don't care which one) from the array. Obvisously I can't store the relationship in a database and the string passed to the GiveMeAKey method can be any URL. I wonder if there is a way of doing that ?

    Read the article

  • Fast matrix transposition in Python

    - by psihodelia
    Is there any fast method to make a transposition of a rectangular 2D matrix in Python (non-involving any library import).? Say, if I have an array X=[[1,2,3], [4,5,6]] I need an array Y which should be a transposed version of X, so Y=[[1,4],[2,5],[3,6]].

    Read the article

  • Finding users near other user

    - by Bunny Rabbit
    what algorithms should I explore to implement a feature which lets a user find other user located near him , the latitude and the longitudes of all the user are known in advance and are fixed [not dynamic]. Also i believe that there should be a better way to store such data then simply storing the lat , long of the user against his user id in a database.What are the efficient ways to handle this ?

    Read the article

  • question about interface

    - by davit-datuashvili
    i have posted this question http://stackoverflow.com/questions/2874487/how-can-i-implement-this-python-snippet-in-java i have compiled it now i need to use in main project public static void main(String[]args){ } ? can anybody show me example?

    Read the article

  • question about interface

    - by davit-datuashvili
    i have posted this question http://stackoverflow.com/questions/2874487/how-can-i-implement-this-python-snippet-in-java i have compiled it now i need to use in main project public static void main(String[]args){ } ? can anybody show me example?

    Read the article

  • question about interface

    - by davit-datuashvili
    i have posted this question http://stackoverflow.com/questions/2874487/how-can-i-implement-this-python-snippet-in-java i have compiled it now i need to use in main project public static void main(String[]args){ } ? can anybody show me example?

    Read the article

  • Scaling vectors from a center point?

    - by user146780
    I'm trying to figure out if I have points that make for example a square: * * * * and let's say I know the center of this square. I want a formula that will make it for eample twice its size but from the center * * * * * * * * Therefore the new shape is twice as large and from the center of the polygon. It has to work for any shape not just squares. I'm looking more for the theory behind it more than the implementation. Thanks

    Read the article

< Previous Page | 93 94 95 96 97 98 99 100 101 102 103 104  | Next Page >