DEV Community

vishal.codes
vishal.codes

Posted on

Day 22/366

πŸš€ Today's Learning:

🌟 DSA

  • Convert infix to postfix expression
  • Find middle element of a stack

🌟 Dev

  • CORS

πŸ” Some Key Highlights:

DSA

To convert an infix expression to postfix expression, you'd iterate through each element in the infix expression. When encountering an operand, you output it directly. When encountering an operator, you push it onto a stack, respecting operator precedence. If an operator with lower precedence is on top of the stack, you pop it and output it. After processing the entire expression, you pop and output all remaining operators from the stack. This process ensures the postfix expression maintains the correct order of operations.

Deleting the middle element of a stack involves iterating through the stack while pushing elements onto a temporary stack until reaching the middle element, which is then discarded. Afterward, continue pushing the remaining elements from the original stack onto the temporary stack. Finally, pop and discard elements from the temporary stack while pushing them back onto the original stack, effectively removing the middle element. This operation maintains the order of the stack's elements while removing the middle one.

DEV

Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers to control how web pages from different origins can interact with each other. When a web page makes a request to a different origin (i.e., domain, protocol, or port), the browser checks if the server of the requested resource allows such cross-origin requests.

If the server allows it by including specific CORS headers in its response, such as Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers, then the browser allows the request to proceed. Otherwise, it blocks the request to prevent potential security vulnerabilities, like cross-site scripting (XSS) and cross-site request forgery (CSRF). This mechanism helps protect user data and ensures secure communication between different origins on the web.

#100daysofcode #dsa

Top comments (0)