#linked_list
Explore tagged Tumblr posts
devsnews · 2 years ago
Link
Many Linked list variations are based on the basic linked list structure but have been modified to better suit a particular application. Examples of linked list variations include doubly linked lists, circular linked lists, skip lists, and XOR-linked lists. This article will describe the doubly linked list as a variation of the singly linked list and its implementation in C++.
0 notes
amansingh10 · 4 years ago
Link
Example:  The given linked list is 2 -> 4 -> 6 -> 8 ->10 then the output will be 2 -> 4 -> 8 -> 10.
If the given linked list has an even number of nodes, then there are two middle nodes, and we are required to delete the second middle element of the linked list.
Example:  The given linked list is 2 -> 4 -> 6 -> 8 ->10 -> 12 then the output will be
2 -> 4 -> 6 ->10 -> 12
0 notes
nhanthanh · 4 years ago
Text
Linked list
Là cấu trúc dữ liệu gồm dãy các node kết nối với nhau thông qua các link (liên kết). 
Mỗi node bao gồm data và address của node kế tiếp.
struct node 
     int data; 
     struct node *next; 
};
Một linked-list (singly-linked list) cơ bản sẽ giống như sau:
Tumblr media
class linked_list 
     private: 
          node *head,*tail; 
     public: 
     linked_list()
     { 
          head = NULL; 
          tail = NULL; 
     } 
};
Một linked-list sẽ bắt đầu từ node head và kết thúc ở node tail.
Ta tạo thêm function để thêm node vào linked-list:
void add_node(int n) 
     node *tmp = new node; 
     tmp->data = n; 
     tmp->next = NULL; 
     if(head == NULL) 
     { 
          head = tmp; 
          tail = tmp; 
     } 
else 
     { 
          tail->next = tmp; 
          tail = tail->next; 
     } 
}
0 notes
christophwagner · 6 years ago
Text
Elixir and Phoenix – A Review
So I've been spending some time recently learning about Elixir and Phoenix. I thought I'd share my experiences here, maybe someone will find it useful. If you've never heard of it, Elixir is a new(-ish) programming language that borrows a lot of syntax from Ruby. However, even though it looks quite similar on the surface, it's really a very different language.
Ruby is a object oriented, multi-paradigm language (meaning it supports imperative and functional programming styles). It's also interpreted, meaning that there is no compilation step. This is what makes many of the advanced features in Ruby work, but it's also the reason why it is rather slow compared to languages like Java or C, which involve a compilation step.
Elixir is similar to Java, in the sense that there is a compiler, but instead of machine code, it produces byte code that runs on a virtual machine. In the case of Elixir, this virtual machine is Erlang, a language created over 30 years ago by the Swedish telecom company Ericsson for use in their telecommunications equipment.
It turns out that Erlang has many features that are very desirable for building web applications, such as high performance, fault tolerance, and the ability to support many millions of simultaneous connections. It also has very good support for multi-core CPUs, something that is more and more important these days, now that even the smartphone in your pocket likely has multiple cores. However, Erlang's syntax is quite dated, so Elixir aims to bring Erlang into the 21st century.
Phoenix on the other hand is a web framework for Elixir. It's heavily inspired by Ruby on Rails and indeed shares many of the same features. However, it is generally at least an order of magnitude faster. Instead of taking several milliseconds, it can answer most requests in a matter of microseconds.
There is a cost, however, and that's learning a new programming paradigm. Elixir is a functional programming language, meaning that there are no objects, only functions. Furthermore, functions have to be "pure" in the mathematical sense, that is, they can have no side effects.
All data in Elixir is immutable by default, meaning it cannot be changed. If you want to make changes to a variable, you need to return a new copy that includes the changes. If this sounds expensive to you, then keep in mind that the developers thought of this and heavily optimized the compiler for this use case, so in practice, this is much faster that you'd think. Behind the scenes, the language uses many tricks to make this incredibly cheap. For example, inserting an element at the beginning of a linked list does not need to copy the entire list – since the tail of the list is guaranteed to never change, the new list can be constructed by simply making a new head and linking it to the old list.
The advantage of having immutable data is that it allows for easy parallelization. The biggest problem that languages like Ruby have with parallelization is when data needs to be shared between two threads. If two separate threads want to access the same data (say, one wants to read and another wants to write), that creates a conflict. They have to synchronize somehow, so that one thread has to wait until the other is done before accessing the shared data. This can lead to many difficult-to-resolve bugs.
In Elixir, everything is immutable, so there is no problem sharing data between threads. If one thread wants to make changes, it automatically gets its own copy of the data.
While it takes a bit of practice, but after a while it's not that difficult thinking only in functions. A web server is really just a collection of functions (AWS lambda makes that pretty clear). A request, consisting of HTTP method, URL, headers and body (for POST/PUT/PATCH) goes in, HTML comes out. Since HTTP is by definition a stateless protocol, the functional paradigm is a perfect match for this use case.
Of course, in a web app, it usually takes many steps to produce the desired response. Phoenix gives you the tools to compose your functions out of many smaller functions, and it also provides a convention to help organize them in a sensible way.
Similar to Rails, Phoenix uses the MVC (Model, View, Controller) pattern, but it introduces a few more layers to keep things neat. In Phoenix, every controller has a single view module, which in turn can have several templates. Any helper functions that are used in the view (which go into a helper module in Rails) go into the view module, assuring that they are only available to the templates that need them, not application-wide like in Rails.
Phoenix also adds a new layer of abstraction between controllers and models (called a “context”), which absorbs all the database queries. This fixes a big problem with Rails, where models often grow tremendously large because they have to deal with both business logic and database logic. Phoenix draws a clear line, separating the business logic from the database code.
Another interesting aspect of Phoenix is the idea of pipelines, which fixes another big problem of Rails: middleware. If you've ever worked on a large Rails app, it can be quite difficult figuring out exactly what filters are run for a request and in what order. Even more so if you have an application that has both an HTML frontend and an API — In this case, you often want a different set of filters to apply for API requests than you have for HTML requests. Phoenix solves this by letting you combine all the filters (which it calls "plugs") into a pipeline and then giving you a way to decide which pipeline a request should be routed through. If it's a browser request, you send it through the :browser pipeline. If it’s an API request, you send it through the :api pipeline. Neat.
All in all, it makes for quite an interesting framework. While I wouldn't exactly recommend it to someone brand new to web programming (Rails is much more beginner friendly than Phoenix), it's easy enough to pick up for someone with a few years of Rails on their back. It does take some getting used to, however – especially Ecto, the persistence layer, feels rather clunky compared to elegance of Rails's ActiveRecord (although it is no less powerful). However, the enormous performance gain might well be worth making the switch for. A single app server running Elixir and Phoenix can easily replace 10 Rails servers (and probably have room left to grow). I'm looking forward to learn more in the future.
0 notes
emblogicrcdlabs · 5 years ago
Text
LINKED LIST
What is Linked list ? Just as the name suggests LINKED LIST it is a list of data that is connected in a such a way that the address of next element or data is stored in the previous data . To access the linked list all we need to do is access the address of first element and that will automatically print the whole list ( because every element is connected with each other).
Why do we use it ? As we know in ARRAY we can store data of similar data type. So array has this con that it can only store data of similar data type. So to overcome this we introduced Linked List . A linked List can store data of multiple data types . This is the main advantage of using a Linked List . Another advantage of using Linked List is the operation of insertion and deletion become easy. Because a LINKED LIST IS MADE UP OF VARIOUS *NODES ( A Node is nothing but it is a structure that holds a data of any data type and Address of type structure). How to use it ? Declaration: struct Linked_List { int Data; struct Linked_List *Node; } This structure has data of data type int and its second variable of struct type Linked_List *Node is used to hold the address of next variable . For making a linked list we need to malloc (to allocate the memory for every node) every single node. As many elements as we want to enter.
-----IMP---- The head node of a linked list should be fixed so that we can access whole Linked list. If we will delete the Head node of the linked list the whole linked list will get destroyed and will get lost in the memory space (as observed) . To End a Linked list we must need to store the Null instead of address so that it won’t access any other .           Figure
Head Node
End Node
Operations we can perform
We can perform various operations like insertion , deletion and sorting etc. To perform any operation first we have to know about the position the pointer where it actually is present , which element or node is it representing at present . While making a head node we introduce a variable of type structure that is defined above named temp . All the operations that we want to perform on linked list is performed by the help of temp variable . We never move head node anywhere (Head node is fixed ) . According to our operation we write algo and make functions .
Techniques Using Linked List Stacks – Works on LIFO Technique (Last In First Out) Queues – Works on FIFO Technique (First In First Out)
Types of Linked List Singly Linked List – In this each node has data and pointer      pointing towards next Node . As mentioned above in Figure . Doubly Linked List - In this we add a pointer to the previous node . Thus we can go in both forward and backward direction
Circular Linked List – In this the end node of Linked list holds the address of the head node . So it makes up a circle .
0 notes
amansingh10 · 4 years ago
Link
In this article, we are going to learn how to merge two linked lists. Here we have given two linked lists that are sorted in increasing order, and we need to merge them into one list, which will also be in increasing order.
Example:
Suppose, the first linked list is 3 -> 5 -> 8 and the second linked lists is 2 -> 4 -> 6. Now, we will merge them into one list and the pointer to the head node of the merged list will return 2 -> 3 -> 4 -> 5 -> 6 -> 8.
0 notes
amansingh10 · 4 years ago
Link
This article explains how to get the middle element of a linked list. Here, we are going to take a singly linked list and find the middle element of the given linked list.
Example: The given linked list is 2 -> 4 -> 6 -> 8 ->10 then the output will be 6.
If the given linked list has an even number of nodes, then there are two middle nodes, and we are required to print the second middle element of the linked list.
Example:  The given linked list is 2 -> 4 -> 6 -> 8 ->10 -> 12 then the output will be 8.
0 notes
amansingh10 · 4 years ago
Link
We can clone a linked list with random numbers by maintaining a hash table. The hash table stores the mapping from a linked list node to its clone.
Algorithm: –
Firstly, we will create the copy of node1 and then add or insert it between node1 and node2 in the ori Linked List. After that, we will create a copy of node2 and add it between node2 and node3 in ori and so on, add the copy of N after the nth node.
Next, we will copy the given arb(arbitrary) link in the below fashion.
ori->next->arb = ori->arb->next;
Now, we restore the ori linked list and copy linked list in the below fashion in a single loop.
ori->next = ori->next->next;
  copy->next = copy->next->next;
Then we are required to confirm the ori->next is null. If it null, return the cloned list.
0 notes
amansingh10 · 4 years ago
Link
Input: List = 2 ->4 ->7 ->4 ->2 ->12 ->0
Output: 5
The longest palindrome list is 2 ->4 ->7 ->4 ->2
Input:List = 12 ->5 ->5 ->3 ->11
Output:2
The longest palindrome list is 5 -> 5
Method:
There is a simple solution available for this problem, we can copy the linked list to the array and try to find the longest palindromic subarray in the array, but this solution is not allowed here because this solution requires extra space. So we will see another method for the given problem.
Another concept is based on the iterative linked list reverse process. We will traverse the given linked list and reverse one by one every prefix of the linked list from the left side. After this, we will find the longest common list beginning from the reversed prefix and the list after the reversed prefix.
0 notes