Roscoemanuelmelissa's Profile

190
Points

Questions
36

Answers
45

  • Asked on July 16, 2020 in .NET.

    LinkedList<T> is a doubly-linked list: each node has references to the nodes before and after.

    head is the first element in the list, but its prev member points to the last element in the list. You can see this from the Last property:

    public LinkedListNode<T> Last {     get { return head == null? null: head.prev;} } 

    This relationship between the last element of the list and head is two-way: head.prev is the last element in the list, and the last element in the list’s next is head.

    So:

    // Remember that 'node' is the 'head'. I've replaced 'node' with  // 'head' to make this clearer.  // The new node's 'next' points to 'head', as it should newNode.next = head;  // The new node's 'prev' points to the old last element in the list // (remember that 'head.prev' is the last element in the list) newNode.prev = head.prev;   // 'head.prev' is the old last element in the list. This is now the second-last // element in the list, and its 'next' should be our new node. This // is the reciprocal of 'newNode.prev = head.prev' head.prev.next = newNode;  // head.prev now points to the new node, as it should. This is the reciprocal of // 'newNode.next = head' head.prev = newNode;  

    To attempt to draw the ‘before’ state:

                           LinkedList                             |                             v  oldLastNode <-- prev --   head                           -- next -->   

    After:

                                               LinkedList                                                 |                                                 v  oldLastNode <-- prev --  newNode <-- prev --  head                           -- next -->          -- next --> 

    So we want to do:

    oldLastNode.next = newNode newNode.prev = oldLastNode  newNode.next = head head.prev = newNode 

    From the first diagram, we can see that oldLastNode is the old head.prev. So as long as we make changes to head.prev before we re-assign head.prev, we can write this as:

    head.prev.next = newNode newNode.prev = head.prev  newNode.next = head head.prev = newNode 

    These are the same operations as in your question, but re-arranged.

    • 74 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    If you want to fill the last order only, then you’ll need to filter out all "older" rows. You can do this by adding the following extra condition to the WHERE clause:

    SELECT Date,AvailStock.Commodity,         AvailStock.SalePrice,PurchPrice,AvailStock.Qty From Purchase Inner Join AvailStock            On Purchase.SalePrice = AvailStock.SalePrice          And Purchase.Commodity = AvailStock.Commodity  Where AvailStock.Commodity ='A'         And AvailStock.Qty!=0         and (AvailStock.Commodity, AvailStock.SalePrice, Purchase.Date) in (   select p.Commodity, p.SalePrice, max(date)   from Purchase p   join AvailStock a on a.Commodity = p.Commodity                     and a.SalePrice = p.SalePrice   group by p.Commodity, p.SalePrice )            

    EDIT for performance

    The following indexes can theoretically improve the performance of this query:

    create index ix1 on AvailStock (Commodity, Qty);  create index ix2 on Purchase(Commodity, SalePrice, Date);  create index ix3 on AvailStock (Commodity, SalePrice); 
    • 58 views
    • 1 answers
    • 0 votes
  • Your CSV should work fine. You just need to Load Data Infile

    You will likely need to define these settings though

    LOAD DATA INFILE 'c:/tmp/discounts.csv'  INTO TABLE discounts  -- comma seperated? maybe pipes '|'? FIELDS TERMINATED BY ','  -- what surrounds input and is it optional? then add OPTIONALLY before ENCLOSED ENCLOSED BY '"' -- what is at the end of files LINES TERMINATED BY '\n' -- how many header rows are there, if any? IGNORE 1 ROWS; 
    • 71 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    We can do max then eq

    df=df.eq(df.max(axis=1),axis=0).astype(int)    v1  v2  v3 0   0   1   0 1   0   1   0 2   0   0   1 
    • 74 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Numpy.

    Use np.where .str.contains and regex first word` in phrase. So that;

    #np.where(if product_name has WomenORMen, 1st Word in Phrase, otherwise;unisex)     df['Gender']=np.where(df.product_name.str.contains('Women|Men')\                       ,df.product_name.str.split('(^[\w]+)').str[1],'Unisex')         product_name  price  gender 0   Women's pant   20.0   Women 1    Men's Shirt   30.0     Men 2  Women's Dress  640.0   Women 3    Blue Shirt    30.0  Unisex 
    • 59 views
    • 4 answers
    • 0 votes
  • Asked on July 16, 2020 in php.

    Go to Settings ยป Permalinks, and simply click on the Save Changes button. This will update your permalinks settings and flush rewrite rules. In most cases, this solution fixes the WordPress posts 404 error. However, if it does not work for you, then you probably need to update your .htaccess file manually.

    You can also manually add this code in your .htaccess file:

    # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 
    • 53 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in HTML.

    HTML Isn’t the best to do that, you can use JS or PHP as a backend and when a user enters your site he simply sends some sessions then you can show how many are they.

    • 48 views
    • 2 answers
    • 0 votes
  • You can only have 1 onclick attribute, so either call the C## method from JS or call the JS code from C#. In both cases you will need Interop, there is no support for combining this in the way you are trying to.

    the "Test()" function is executed automatically

    Yes, in onclick="... @Test()" it is executed when the page renders, not when the button is clicked.

    • 75 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in HTML.

    I actually found too that the Logout button won’t work since it’s type is button and not submit therfore the post wasn’t submitted and the isset($_POST['logout']) never worked.

    • 66 views
    • 3 answers
    • 0 votes
  • Asked on July 16, 2020 in HTML.

    If I understand you correctly, in the case of the sample in your question, an xpath expression like this may do the trick:

    //div[contains(@class, "css-1x9zltl")]["Elixir Developer"]/ancestor::div[@class="css-fxb39h"][1]/following-sibling::div [@class="css-m6o8yl"]//div[@class="css-ajz12e"]/text() 

    This expression basically locates the <div> node meeting your class and text conditions, goes up to the first ancestor which is a sibling of the <div> node in which the target text is buried, then goes down to the <div>child node (of that sibling) which contains the target text, and finally selects the text node of that child node.

    • 56 views
    • 2 answers
    • 0 votes