<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ujjwal Sinha</title>
    <description>The latest articles on DEV Community by Ujjwal Sinha (@believer15).</description>
    <link>https://dev.to/believer15</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1194889%2F86394a95-6372-403c-a73b-4ae09e9ff8c4.png</url>
      <title>DEV Community: Ujjwal Sinha</title>
      <link>https://dev.to/believer15</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/believer15"/>
    <language>en</language>
    <item>
      <title>Handle Form State in React</title>
      <dc:creator>Ujjwal Sinha</dc:creator>
      <pubDate>Tue, 28 Jan 2025 07:16:43 +0000</pubDate>
      <link>https://dev.to/believer15/handle-form-state-in-react-34c8</link>
      <guid>https://dev.to/believer15/handle-form-state-in-react-34c8</guid>
      <description>&lt;p&gt;Handle Form State in React is used to update the state of a component when the user interacts with an input field (e.g., typing in a text box, selecting an option, etc.). It is a fundamental part of handling form inputs in React.&lt;/p&gt;

&lt;p&gt;Let’s break down how it works, its use cases, and how you can extend it to perform specific actions (like when the user is on the &lt;code&gt;mobile_number&lt;/code&gt; field).&lt;/p&gt;

&lt;h2&gt;
  
  
  How Input Change Handler Works
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Event Object:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When the user types in an input field, an onChange event is triggered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This event contains information about the input field, such as its name and value.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Updating State:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The input change handler extracts the name and value from the event object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It then updates the corresponding state property using the setState function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Dynamic State Updates:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By using the name attribute of the input field, the handler can dynamically update the correct property in the state object.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Basic Input Change Handler
&lt;/h2&gt;

&lt;p&gt;Here’s a simple example of an input change handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleInputChange = (e) =&amp;gt; {
  const { name, value } = e.target; // Extract name and value from the event
  setFormState({
    ...formState, // Spread the existing state
    [name]: value // Update the specific field
  });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use Cases for Input Change Handler
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Form Handling:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Update form state as the user types in input fields.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable/disable buttons or show/hide elements based on form state.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Validation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Perform real-time validation (e.g., check if an email is valid or if a password meets requirements).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Dynamic Behavior:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trigger specific actions when the user interacts with a particular field (e.g., auto-format a phone number or show suggestions).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Conditional Rendering:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show or hide additional fields based on user input.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advanced Use Case: Perform Actions Based on the Active Field
&lt;/h2&gt;

&lt;p&gt;If you want to perform specific actions when the user is interacting with a particular field (e.g., mobile_number), you can extend the input change handler to include conditional logic.&lt;/p&gt;

&lt;p&gt;Example: Auto-Format Mobile Number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleInputChange = (e) =&amp;gt; {
  const { name, value } = e.target;

  // Perform specific actions based on the field name
  if (name === 'mobile_number') {
    // Auto-format mobile number (e.g., add dashes)
    const formattedValue = value.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
    setFormState({
      ...formState,
      [name]: formattedValue
    });
  } else {
    // Update other fields normally
    setFormState({
      ...formState,
      [name]: value
    });
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>webdev</category>
      <category>redux</category>
      <category>frontend</category>
    </item>
    <item>
      <title>How Error.CaptureStackTrace Works!</title>
      <dc:creator>Ujjwal Sinha</dc:creator>
      <pubDate>Mon, 23 Dec 2024 08:02:09 +0000</pubDate>
      <link>https://dev.to/believer15/how-errorcapturestacktrace-works-3807</link>
      <guid>https://dev.to/believer15/how-errorcapturestacktrace-works-3807</guid>
      <description>&lt;p&gt;&lt;code&gt;Error.captureStackTrace(this, this.constructor)&lt;/code&gt; is a method provided by the V8 JavaScript engine (used in Node.js and Chrome). It is used to create a stack trace for an error object, allowing developers to track where the error originated in the code. Here’s a detailed explanation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Breakdown of Error.captureStackTrace&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1-What is &lt;code&gt;Error.captureStackTrace&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s a static method of the Error class in V8-based JavaScript environments.&lt;br&gt;
It customizes the stack trace associated with an error object (&lt;code&gt;this&lt;/code&gt; in this case).&lt;br&gt;
&lt;strong&gt;2-Parameters of &lt;code&gt;Error.captureStackTrace&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt;: Refers to the error object that is being constructed (e.g., the &lt;code&gt;AppError&lt;/code&gt; instance).&lt;br&gt;
&lt;code&gt;this.constructor&lt;/code&gt;: Specifies the constructor function (in this case, &lt;code&gt;AppError&lt;/code&gt;) to exclude from the stack trace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
The method populates the &lt;code&gt;stack&lt;/code&gt; property of the error object.&lt;br&gt;
The stack trace provides a detailed list of function calls leading up to the point where the error was created.&lt;br&gt;
By passing &lt;code&gt;this.constructor&lt;/code&gt;, it removes the &lt;code&gt;AppError&lt;/code&gt; constructor itself from the stack trace, making the output cleaner and more focused on the actual location of the error.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Why Use It?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1- Clean Stack Traces:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Including the constructor in the stack trace often adds unnecessary noise.&lt;br&gt;
By omitting it, the trace starts from the point where the error was thrown or created, making debugging easier.&lt;br&gt;
&lt;strong&gt;2-Custom Error Classes:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In custom error classes, you typically want the stack trace to reflect where the error occurred in user code, not where the custom error was constructed.&lt;br&gt;
Example&lt;br&gt;
Here’s a practical example to demonstrate its use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AppError extends Error {
    constructor(message, statusCode) {
        super(message);
        this.statusCode = statusCode;
        Error.captureStackTrace(this, this.constructor);
    }
}

// Simulate an error in a function
function faultyFunction() {
    throw new AppError("Something went wrong!", 500);
}

try {
    faultyFunction();
} catch (err) {
    console.log(err.stack);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output Without &lt;code&gt;Error.captureStackTrace&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
The stack trace might include the &lt;code&gt;AppError&lt;/code&gt; constructor, which is less relevant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AppError: Something went wrong!
    at new AppError (/path/to/file.js:10:9)
    at faultyFunction (/path/to/file.js:15:11)
    at Object.&amp;lt;anonymous&amp;gt; (/path/to/file.js:18:1)
    ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output With &lt;code&gt;Error.captureStackTrace&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
The constructor (new &lt;code&gt;AppError&lt;/code&gt;) is omitted, making the stack trace cleaner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AppError: Something went wrong!
    at faultyFunction (/path/to/file.js:15:11)
    at Object.&amp;lt;anonymous&amp;gt; (/path/to/file.js:18:1)
    ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Error.captureStackTrace(this, this.constructor)&lt;/code&gt; enhances stack trace readability by focusing on where the error occurred rather than its construction. This is particularly useful in custom error classes for debugging complex applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Implementation of Stack Using Array</title>
      <dc:creator>Ujjwal Sinha</dc:creator>
      <pubDate>Fri, 17 Nov 2023 15:27:03 +0000</pubDate>
      <link>https://dev.to/believer15/implementation-of-stack-using-array-1h55</link>
      <guid>https://dev.to/believer15/implementation-of-stack-using-array-1h55</guid>
      <description>&lt;p&gt;In this Article, We will learn how we can Implementation our own &lt;strong&gt;Stack&lt;/strong&gt; and Use it. I'm using java but you can use whatever language you comfortable with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt; :- You must be familiar with classes and object to implement stack.&lt;/p&gt;

&lt;p&gt;Before Moving to Implementation, Let's have look to this &lt;a href="https://dev.to/believer15/understanding-stack-data-structure-and-real-world-use-cases-1a1o"&gt;What is tack? What Operation we can perform?&lt;/a&gt; for better understanding.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;How Stack Works ? *&lt;/em&gt;&lt;br&gt;
As we know stack is linear data structure and follows the particular order to perform operations which standardize on LIFO principle.&lt;br&gt;
Whatever the stack does it maintain the discipline to perform operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;for example&lt;/strong&gt; : In array we can access data using index in O(1) operation but in stack we can't do. So here we follow certain order to perform this task in stack in O(n).&lt;br&gt;
Keeping this thing in mind we move to implementation part.&lt;/p&gt;
&lt;h2&gt;
  
  
  List of the function
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Brief introduction which we're going to implement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;push():&lt;/strong&gt; When we insert an element in a stack then the operation is known as a push. If the stack is full then the overflow condition occurs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pop():&lt;/strong&gt; When we delete an element from the stack, the operation is known as a pop. If the stack is empty means that no element exists in the stack, this state is known as an underflow state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;isEmpty():&lt;/strong&gt; It determines whether the stack is empty or not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;isFull():&lt;/strong&gt; It determines whether the stack is full or not.'&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;peek():&lt;/strong&gt; It returns the element at the given position.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;count():&lt;/strong&gt; It returns the total number of elements available in a stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;display():&lt;/strong&gt; It prints all the elements available in the stack.&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementation Using Array
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Initialize the class&lt;/strong&gt; &lt;br&gt;
Declare variable array as 'arr' and integer with index 0;&lt;br&gt;
Note:- Behind the scene, Array work as stack. So, don't be amazed. Just know these thing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static class Stack {
        int[] arr = new int[5];
        int idx = 0;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Defining Methods in class Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Push Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- The push method takes an integer parameter x, representing the element to be pushed onto the stack.&lt;br&gt;
2- It checks if the stack is full by calling a method isFull().&lt;br&gt;
3- If the stack is full, it prints "Stack is Full" to the console and returns, indicating that the push operation cannot be performed.&lt;br&gt;
4- If the stack is not full, it assigns the value of x to the next available position in the stack array (arr) at index idx.&lt;br&gt;
5- The index idx is then incremented, possibly pointing to the next available position for the next push operation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void push(int x){
     if(isFull()){
         System.out.println("Stack is Full");
         return;
     }
     arr[idx] = x;
     idx++;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Peek Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- The peek method takes no parameters but uses the instance variable idx to determine the top of the stack.&lt;br&gt;
2- It checks if the stack is empty by verifying if the index idx is equal to 0.&lt;br&gt;
3- If the stack is empty, it prints "Stack Empty" to the console and returns -1, indicating that there is no valid element to peek.&lt;br&gt;
4- If the stack is not empty, it returns the value of the element at the top of the stack. The index idx-1 is used because the top element is at one position below the current value of idx.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int peek(){
    if(idx == 0){
        System.out.println("Stack Empty");
        return -1;
    }
    return arr[idx-1];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pop Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- The pop method is used to remove and return the element at the top of the stack.&lt;br&gt;
2- It checks if the stack is empty by verifying if the index idx is equal to 0.&lt;br&gt;
3- If the stack is empty, it prints "Stack is Empty" to the console and returns -1, indicating that there is no valid element to pop.&lt;br&gt;
4- If the stack is not empty:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It retrieves the value of the element at the top of the stack (arr[idx - 1]) and stores it in a variable named top.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sets the element at the top of the stack to 0, essentially removing it from the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decrements the index idx to point to the next available position in the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns the value of the removed element (top).&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int pop() {
  if(idx == 0){
      System.out.println("Stack is Empty");
      return -1;
  }
  int top = arr[idx -1];
  arr[idx-1] = 0;
  idx--;
  return top;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Display Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- The display method is responsible for printing the contents of the stack to the console.&lt;br&gt;
2- It uses a for loop to iterate over the elements of the stack array (arr) from index 0 to idx-1.&lt;br&gt;
3- Inside the loop, it prints each element followed by a space.&lt;br&gt;
4- After the loop, it prints a newline character (System.out.println()) to move to the next line in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void display(){
     for(int i = 0; i &amp;lt;= idx-1; i++){
         System.out.print(arr[i] + " ");
     }
     System.out.println();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;isEmpty Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;IsEmpty return boolean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean isEmpty(){
   if(idx == 0) return true;
   else return false;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Size/Count Method&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int size() {
    return idx;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;isFull Method&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean isFull(){
   if(idx == arr.length) return true;
   else return false;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>java</category>
      <category>dsa</category>
      <category>programming</category>
      <category>stack</category>
    </item>
    <item>
      <title>Understanding Stack Data Structure and Real-World Use Cases</title>
      <dc:creator>Ujjwal Sinha</dc:creator>
      <pubDate>Wed, 08 Nov 2023 16:10:43 +0000</pubDate>
      <link>https://dev.to/believer15/understanding-stack-data-structure-and-real-world-use-cases-1a1o</link>
      <guid>https://dev.to/believer15/understanding-stack-data-structure-and-real-world-use-cases-1a1o</guid>
      <description>&lt;p&gt;In this Article, we'll explore about Stack &amp;amp; its methods and&lt;br&gt;
Real-life Use Cases of Stack and Best Practice to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Stack ?
&lt;/h2&gt;

&lt;p&gt;Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first, comes out last.&lt;/p&gt;

&lt;p&gt;In other words, a stack can be defined as a container in which insertion and deletion can be done from the one end known as the top of the stack.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3YSllX4J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmnowh59tm0713omqojk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3YSllX4J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmnowh59tm0713omqojk.jpg" alt="Image description" width="605" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Operation on Stack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;push():&lt;/strong&gt; When we insert an element in a stack then the operation is known as a push. If the stack is full then the overflow condition occurs.&lt;br&gt;
&lt;strong&gt;pop():&lt;/strong&gt; When we delete an element from the stack, the operation is known as a pop. If the stack is empty means that no element exists in the stack, this state is known as an underflow state.&lt;br&gt;
&lt;strong&gt;isEmpty():&lt;/strong&gt; It determines whether the stack is empty or not.&lt;br&gt;
&lt;strong&gt;isFull():&lt;/strong&gt; It determines whether the stack is full or not.'&lt;br&gt;
&lt;strong&gt;peek():&lt;/strong&gt; It returns the element at the given position.&lt;br&gt;
&lt;strong&gt;count():&lt;/strong&gt; It returns the total number of elements available in a stack.&lt;br&gt;
&lt;strong&gt;change():&lt;/strong&gt; It changes the element at the given position.&lt;br&gt;
&lt;strong&gt;display():&lt;/strong&gt; It prints all the elements available in the stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applications of Stack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mathematical expression&lt;/strong&gt;: Stacks are used to evaluate mathematical expressions, such as infix, postfix, and prefix expressions. They are also used to convert one expression to another.&lt;br&gt;
&lt;strong&gt;Backtracking:&lt;/strong&gt; Stacks are used in backtracking algorithms to keep track of the path taken to reach a particular point in the algorithm.&lt;br&gt;
&lt;strong&gt;Function call:&lt;/strong&gt; Stacks are used to keep track of function calls and return addresses in programming languages.&lt;br&gt;
&lt;strong&gt;Memory Management:&lt;/strong&gt; Stacks are used in memory management to allocate and deallocate memory for variables and data structures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Stacks are simple to implement and can be created using arrays, linked lists, or even dynamic memory allocation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stacks are efficient in memory management as they only allocate memory for the elements that are currently in the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The push and pop operations have O(1) time complexity, which means that take constant time regardless of the size of the stack.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Static stacks have a fixed size, which means that in a stack we can add limited elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stacks can suffer from &lt;strong&gt;overflow&lt;/strong&gt; when you try to add more elements than the stack size, and &lt;strong&gt;underflow&lt;/strong&gt; when you try to remove an element from an empty stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stacks can only be used to store and retrieve data in a specific order, whereas queues and trees can be used to store and retrieve data in a variety of orders.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Use Cases of Stack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Web Browsers:&lt;/strong&gt; Web browsers use stacks to keep track of the history of websites you visit.&lt;br&gt;
Call Logs: Call logs in mobile phones use stacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text Editors:&lt;/strong&gt; Text editors like Microsoft Word, Excel, or Notepad use stacks for their undo or redo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax Parsing:&lt;/strong&gt; Syntaxes in languages are parsed using stacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Converting Infix to Postfix Expressions:&lt;/strong&gt; Stacks are used to convert infix to postfix expressions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Message Logs:&lt;/strong&gt; Message logs and all messages you get are arranged in a stack.&lt;/p&gt;

</description>
      <category>stack</category>
      <category>webdev</category>
      <category>java</category>
      <category>dsa</category>
    </item>
    <item>
      <title>Implementation of LinkedList</title>
      <dc:creator>Ujjwal Sinha</dc:creator>
      <pubDate>Sun, 05 Nov 2023 12:07:09 +0000</pubDate>
      <link>https://dev.to/believer15/implementation-of-linkedlist-1eka</link>
      <guid>https://dev.to/believer15/implementation-of-linkedlist-1eka</guid>
      <description>&lt;p&gt;Hey Everyone!!!, Hope! Everyone is doing great.&lt;/p&gt;

&lt;p&gt;In this Article, We will see how we can implement our own LinkedList class and use them. In this Article, I'm using java but you can use whatever language you comfortable with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt; :- You must be familiar with the &lt;strong&gt;Object&lt;/strong&gt; and &lt;strong&gt;class&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We defines a simple implementation of a Node class within an Implementation class. The Node class represents a basic node in a linked list data structure, containing an integer data value and a reference to the next node in the sequence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here the term&lt;/strong&gt; Reference means address of next node in the sequence. As you can see below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cw7OCoyA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz49v3q8y0g43t55616o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cw7OCoyA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz49v3q8y0g43t55616o.jpg" alt="Image description" width="638" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ld_8rjhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t42lqvxu7mqxdu65rqrh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ld_8rjhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t42lqvxu7mqxdu65rqrh.jpg" alt="Image description" width="347" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining a Node Class  (Important)
&lt;/h2&gt;

&lt;p&gt;It is mandatory to Remember this every time we use node type to create node variable. The above code is basic building block of LinkedList Implementation.&lt;/p&gt;

&lt;p&gt;1 -The code defines a Node class within an Implementation class, representing a basic unit for a linked list data structure.&lt;/p&gt;

&lt;p&gt;2-The Node class consists of an integer data field to store data and a next field to hold the reference to the next node in the linked list.&lt;/p&gt;

&lt;p&gt;3-It includes a single-line constructor that initializes the data field of the Node with the value passed as an argument. The next field is not explicitly initialized and defaults to null.&lt;/p&gt;

&lt;p&gt;This Node class forms the foundation for implementing linked lists in Java and can be extended for various data structure and algorithm implementations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CQPJNaFf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4rw2eke67utruoixv4f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CQPJNaFf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4rw2eke67utruoixv4f.png" alt="Image description" width="800" height="608"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining a LinkedList class
&lt;/h2&gt;

&lt;p&gt;As we define the child node class above after that we define another child named LinkedList.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initialization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Initialize then node head, tail with null and size with integer. &lt;/p&gt;

&lt;p&gt;Initialize value with null means when there is a single node in the list it always point to the null and last node of list also always point to the null. If node is not pointing anywhere then it is point to null.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yLKs7lpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vdgt26du90kxpgd9bmpy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yLKs7lpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vdgt26du90kxpgd9bmpy.png" alt="Image description" width="800" height="687"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining Methods in LinkedList&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;InsertAtEnd Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- A method called insertAtEnd in a linked list implementation that adds a new node at the end of the list.&lt;/p&gt;

&lt;p&gt;2- It creates a new node with the provided value and checks if the linked list is empty.&lt;/p&gt;

&lt;p&gt;3- If the list is empty, the new node becomes the head of the list; otherwise, it is appended to the current tail node.&lt;/p&gt;

&lt;p&gt;4- The tail pointer is then updated to the newly added node, ensuring it always points to the last node. Additionally, the size of the linked list is incremented to reflect the addition of the new element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MIr450L7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ribx3wu9md2jfjbiisl6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MIr450L7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ribx3wu9md2jfjbiisl6.png" alt="Image description" width="792" height="930"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;display Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- Method named display within a linked list implementation that prints the elements of the linked list.&lt;/p&gt;

&lt;p&gt;2- It initializes a temporary node temp with the reference to the head of the linked list for traversal.&lt;/p&gt;

&lt;p&gt;3- The method employs a while loop to iterate through the linked list until the temporary node temp becomes null, ensuring all elements are printed.&lt;/p&gt;

&lt;p&gt;4- Within the loop, it prints the data of the current node followed by a space, allowing the elements to be displayed horizontally.&lt;/p&gt;

&lt;p&gt;This display method facilitates the visualization and confirmation of the elements stored in the linked list, enabling users to verify the list's content and structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZRNg3eo---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsn81bxo3rjfgce3iu1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZRNg3eo---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsn81bxo3rjfgce3iu1b.png" alt="Image description" width="800" height="641"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getAt Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- A method named getAt within a linked list implementation, allowing retrieval of the data value of a node at a specified index.&lt;/p&gt;

&lt;p&gt;2- It includes a check to ensure that the provided index is within the valid range of the linked list. If the index is outside the valid range, it prints a "wrong index" message and returns -1.&lt;/p&gt;

&lt;p&gt;3- The method initializes a temporary node temp with the reference to the head of the linked list.&lt;/p&gt;

&lt;p&gt;4- It employs a for loop to traverse the linked list, moving from the head node to the node at the specified index, determined by the loop counter.&lt;/p&gt;

&lt;p&gt;5- The method returns the data value of the node at the specified index if the index is valid, enabling the retrieval of specific data from the linked list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uS3TJg_o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mcbpsq2jto3z33wd819w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uS3TJg_o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mcbpsq2jto3z33wd819w.png" alt="Image description" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;insertAtHead Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- Method called insertAtHead in a linked list implementation, used to add a new node with the specified value at the beginning of the linked list.&lt;/p&gt;

&lt;p&gt;2- It creates a new node with the provided value, initializing the temp variable.&lt;/p&gt;

&lt;p&gt;3- If the linked list is empty (i.e., head is null), the new node becomes both the head and the tail of the list, signifying the first and only node in the list.&lt;/p&gt;

&lt;p&gt;4- If the list is not empty, the new node is inserted at the head, with its next pointer referencing the previous head node, ensuring the continuity of the list.&lt;/p&gt;

&lt;p&gt;This insertAtHead method effectively adds a new node at the beginning of the linked list, updating the necessary pointers and maintaining the list's integrity and size.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eEqQuNhn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6a2wbd0a4lptxig689d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eEqQuNhn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6a2wbd0a4lptxig689d.png" alt="Image description" width="800" height="761"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;insertAt Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- The insertAt method is used to insert a new node with the specified value at the given index in the linked list.&lt;/p&gt;

&lt;p&gt;2- It begins by creating a new node t with the provided value and initializes a temporary node temp with the reference to the head of the linked list.&lt;/p&gt;

&lt;p&gt;3- If the index is equal to the size of the list, the method delegates the task to insertAtEnd to add the new node at the end of the list, and if the index is 0, it delegates the task to insertAtHead to add the new node at the beginning of the list.&lt;/p&gt;

&lt;p&gt;4- If the index is outside the valid range of the list, the method prints a "wrong index" message and returns.&lt;/p&gt;

&lt;p&gt;5- If the index is valid and not at the beginning or end, the method traverses the list to the node just before the specified index.&lt;/p&gt;

&lt;p&gt;6- It then inserts the new node t at the specified index, adjusting the pointers to maintain the list's integrity, and increments the size of the list.&lt;/p&gt;

&lt;p&gt;This insertAt method enables the insertion of a new node at the specified index in the linked list, handling various edge cases and updating the necessary pointers to ensure the list remains intact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EBWA8XQJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ck0o6whokr7qjxz2oofk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EBWA8XQJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ck0o6whokr7qjxz2oofk.png" alt="Image description" width="800" height="886"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;deleteAt Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- The deleteAt method is used to remove the node at the specified index in the linked list.&lt;/p&gt;

&lt;p&gt;2- It initializes a temporary node temp with the reference to the head of the linked list.&lt;/p&gt;

&lt;p&gt;3- If the index is 0, indicating the deletion of the first node, the method updates the head to point to the next node, effectively removing the current head. It also decrements the size of the list and then returns.&lt;/p&gt;

&lt;p&gt;4- If the index is not 0, the method traverses the list to the node just before the specified index.&lt;/p&gt;

&lt;p&gt;5- It adjusts the pointers of the nodes to skip over the node at the specified index, removing it from the linked list. The tail is also updated to point to the new last node.&lt;/p&gt;

&lt;p&gt;6- The size of the list is decremented to reflect the removal of the node.&lt;/p&gt;

&lt;p&gt;This deleteAt method effectively removes the node at the specified index from the linked list, updating the necessary pointers and adjusting the size of the list accordingly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MTg3nBhp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02epnq6q4ubek3uqrgf0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MTg3nBhp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02epnq6q4ubek3uqrgf0.png" alt="Image description" width="800" height="677"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linkedlist</category>
      <category>dsa</category>
      <category>java</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding LinkedList Data Structure and Real-life Use Cases</title>
      <dc:creator>Ujjwal Sinha</dc:creator>
      <pubDate>Fri, 03 Nov 2023 13:24:38 +0000</pubDate>
      <link>https://dev.to/believer15/understanding-linkedlist-data-structure-and-real-life-use-cases-3dk</link>
      <guid>https://dev.to/believer15/understanding-linkedlist-data-structure-and-real-life-use-cases-3dk</guid>
      <description>&lt;p&gt;In this Article, we'll explore about LinkedList &amp;amp; its types and &lt;br&gt;
Real-life Use Cases of LinkedList and Best Practice to use.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is LinkedList ?
&lt;/h2&gt;

&lt;p&gt;LinkedList as a linear data structure where elements are stored in nodes that are linked together by pointers, each containing the data and a reference to the next node. Unlike Arrays, Linked List elements are not stored at a contiguous location. &lt;br&gt;
In a Node, there is data and address/reference of next node and last node always point to null.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;As you can see in image below-&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e9Kz6YwM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw07p42wv3gvtb7qchlc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e9Kz6YwM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw07p42wv3gvtb7qchlc.jpg" alt="Image description" width="600" height="251"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of linked lists
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1- Singly-linked list :-&lt;/strong&gt;In Singly-linked list, We can say that traversal of items can be done in the forward direction only due to the linking of every node to its next node.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operation on Singly-Linked list&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Insertion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deletion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Display&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Below you can see representations-&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--081jFm5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pwzptd6gbeksks48pwu2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--081jFm5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pwzptd6gbeksks48pwu2.jpg" alt="Image description" width="636" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Node Creation-&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct node {
    int data;           // Data 
    struct node * next; // Address 
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2- Doubly-linked list :-&lt;/strong&gt; In Doubly-linked list, We can say that Traversal of items can be done in both forward and backward directions as every node contains an additional prev pointer that points to the previous node.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operation on Doubly-Linked list&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Insertion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deletion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Display&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Representation of Doubly linked list-&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tg9b6bdz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvbgzlckd2y35gtzsvmj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tg9b6bdz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvbgzlckd2y35gtzsvmj.jpg" alt="Image description" width="603" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Node Creation-&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Class for Doubly Linked List
public class DLL {
    Node head; // head of list

    /* Doubly Linked list Node*/
    class Node {
        int data;
        Node prev;
        Node next;

        // Constructor to create a new node
        // next and prev is by default initialized as null
        Node(int d) { 
           data = d; 
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3- Circular linked lists :-&lt;/strong&gt; In Circular linked list, We can say that A circular linked list is a type of linked list in which the first and the last nodes are also connected to each other to form a circle, there is no NULL at the end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operation on Circular Linked list&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Insertion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deletion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Display&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Representation of Circular linked list-&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nxYvp72P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42xofzkfu9u7vfew8sgo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nxYvp72P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42xofzkfu9u7vfew8sgo.jpg" alt="Image description" width="605" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-life Use Cases of LinkedList
&lt;/h2&gt;

&lt;p&gt;find various applications in real-life scenarios due to their dynamic memory allocation and efficient insertion and deletion operations. Here are some real-life use cases of LinkedLists:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Music and Video Playlists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In music and video streaming services, playlists are commonly implemented using LinkedLists. Each song or video is represented as a node, allowing users to easily add, remove, or rearrange the sequence of media items in their playlists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browser History in Web Browsers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Web browsers use LinkedLists to maintain a user's browsing history. Each visited web page is stored as a node, enabling users to navigate backward and forward through their browsing history, facilitating a seamless browsing experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task Management Applications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Task management applications often utilize LinkedLists to manage to-do lists. Each task is stored as a node, enabling users to add new tasks, mark tasks as complete, or reorder tasks based on priority or due dates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scheduling Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In transportation systems, such as train or flight or Bus scheduling, LinkedLists can be used to manage the sequence of upcoming departures. Each departure schedule is stored as a node, allowing for easy rearrangement and adjustment of the schedule based on real-time changes or delays.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/believer15/implementation-of-linkedlist-1eka"&gt;&lt;strong&gt;Check out the Implementation of Linked list&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>java</category>
      <category>linkedlist</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What are Packages and How we can use it?</title>
      <dc:creator>Ujjwal Sinha</dc:creator>
      <pubDate>Wed, 01 Nov 2023 10:29:14 +0000</pubDate>
      <link>https://dev.to/believer15/what-are-packages-and-how-we-can-use-it-1p2m</link>
      <guid>https://dev.to/believer15/what-are-packages-and-how-we-can-use-it-1p2m</guid>
      <description>&lt;p&gt;In this article, We will learn about packages and What is the hierarchy and learn about how Packages contains different class and  methods. This term packages used in every programming languages, so  I though to share my knowledge and some examples to related to topic.&lt;/p&gt;

&lt;p&gt;With term Packages what comes in our mind. Just think once and let me know in the comment. So, what you think that's right!!! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nrc7k1II--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrj1uev05woe8e4e035s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nrc7k1II--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrj1uev05woe8e4e035s.jpg" alt="Image description" width="548" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example :- Packages is same as you might think in general wrapper or box. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But What we say in technical term, What are Packages?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Something that's Packed&lt;/strong&gt; &lt;strong&gt;Right!!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Packages is set of programs files and data files which developer by programmers to perform specific task and include information regarding installation of packages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Or We can say...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A package is a container of a group of related classes where some of the classes are accessible are exposed and others are kept for internal purpose.&lt;br&gt;
We can reuse existing classes from the packages as many time as we need it in our program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the hierarchy of Packages -&amp;gt; Sub-Packages-&amp;gt; classes&lt;/strong&gt;&lt;br&gt;
You can visualize how it is structured inside single package java.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LpeJiWOL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oh9r4u4ss2aswaqwer6q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LpeJiWOL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oh9r4u4ss2aswaqwer6q.jpg" alt="Image description" width="664" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xfo1TYFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1yzzt4x6sle96dv0cel8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xfo1TYFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1yzzt4x6sle96dv0cel8.jpg" alt="Image description" width="515" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, You had a Clear understanding of the what are packages and how it is structured. Now, We move forward and go deep down in packages and it's type? How it works?&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of Packages:-
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZULjyuDH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8rsi43t148liluj0u7q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZULjyuDH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8rsi43t148liluj0u7q.jpg" alt="Image description" width="416" height="285"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  User Defined Packages
&lt;/h2&gt;

&lt;p&gt;These are the packages that are defined by the user. First we create a directory myPackage (name should be same as the name of the package). Then create the MyClass inside the directory with the first statement being the package names.&lt;/p&gt;

&lt;p&gt;for Example :-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Name of the package must be same as the directory
// under which this file is saved
package myPackage;

public class MyClass
{
    public void getNames(String s)
    {        
        System.out.println(s);        
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can use above MyClass class in our program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* import 'MyClass' class from 'names' myPackage */
import myPackage.MyClass;

public class PrintClass 
{
   public static void main(String args[]) 
   {       
      // Initializing the String variable with a value 
      String name = "Casto";

      // Creating an instance of class MyClass in the package.
      MyClass obj = new MyClass();

      obj.getNames(name);
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note :- MyClass.java must be saved inside the myPackage directory since it is a part of the package.&lt;/p&gt;

&lt;h2&gt;
  
  
  Builtin Packages
&lt;/h2&gt;

&lt;p&gt;BuiltIn Packages consist of large number of classes which is defined by java or certain programming language to perform necessary operations.&lt;br&gt;
Built-in packages in Java consist of classes that are part of the Java API.&lt;/p&gt;

&lt;p&gt;Some of the commonly used built-in packages used in java are:-&lt;/p&gt;

&lt;p&gt;1) java.lang:- Contains language support classes.This package is automatically imported.&lt;br&gt;
2)  java.io:- Contains classed for supporting input / output operations.&lt;br&gt;
3)  java.util:- Contains utility classes which implement data structures like Linked List, Dictionary and support,for Date / Time operations.&lt;br&gt;
4)  java.applet:- Contains classes for creating Applets.&lt;br&gt;
5)  java.awt:- Contain classes for implementing the components for graphical user interfaces (like button , ;menus etc).&lt;br&gt;
6)  java.net:- Contain classes for supporting networking operations.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Static import
&lt;/h2&gt;

&lt;p&gt;Static import is a feature introduced in Java programming language ( versions 5 and above ) that allows members ( fields and methods ) defined in a class as public static to be used in Java code without specifying the class in which the field is defined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import static java.lang.System.*; 

class ImportDemo 
{ 
public static void main(String args[]) 
{    
        // We don't need to use 'System.out' 
        // as imported using static. 
        out.println("GeeksforGeeks"); 
} 
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Handling Name Conflicts
&lt;/h2&gt;

&lt;p&gt;The only time we need to pay attention to packages is when we have a name conflict . For example both, java.util and java.sql packages have a class named Date. So if we import both packages in program as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.*;
import java.sql.*;

//And then use Date class, then we will get a compile-time error :

Date today ; //ERROR-- java.util.Date or java.sql.Date?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The compiler will not be able to figure out which Date class do we want. &lt;br&gt;
This problem can be solved by using a specific import statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Date;
import java.sql.*;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we need both Date classes then, we need to use a full package name every time we declare a new object of that class.&lt;br&gt;
For Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java.util.Date deadLine = new java.util.Date();
java.sql.Date today = new java.sql.Date();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Important Points to Remember :-
&lt;/h2&gt;

&lt;p&gt;1- Every class is part of some package.&lt;br&gt;
2- If no package is specified, the classes in the file goes into a special unnamed package (the same unnamed package for all files).&lt;br&gt;
3- All classes/interfaces in a file are part of the same package. Multiple files can specify the same package name.&lt;br&gt;
4- If package name is specified, the file must be in a subdirectory called name (i.e., the directory name must match the package name).&lt;br&gt;
5- We can access public classes in another (named) package using: package-name.class-name&lt;/p&gt;

</description>
      <category>java</category>
      <category>packages</category>
      <category>datastructures</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
