👉Support Us by Sharing our Data Structure Tutorial with others if you really found this tutorial useful and also share your valuable feedback in the comment section below so we can work on them to improve our tutorials 😊.(alert-success)
Data Structure Tutorial | AlgoLesson
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.
Visual Studio Code Setup for Front End Web Development.
The answer to the above question is no, it is not compulsory to have a code editor for writing your frontend code you can use any kind of text editor like notepad for writing your code but having a code editor is very useful because it is designed specifically to help developers with coding.
Why use Visual Studio Code?
Open-source software is software whose source code is publically accessible under a license in which the owner gives permission to users to see or modify the code and they can distribute the source code to anyone for any purpose.(alert-success)
Cross-platform software is that software that is designed to work on several computing platforms like Windows, macOS, and Linux. Example: Visual Studio Code, Firefox, Chrome, etc.(alert-success)
I hope you get some basic idea of a code editor and Visual Studio Code. You can also go through some frequently asked doubt related to the code editor and Visual Studio Code.
Now let's start with the download and installing the part. First, follow the link given below and download the Visual Studio Code (stable build) for your Operating like Windows, macOS, or Linux.
(getButton) #text=(Visual Studio Code) #icon=(download) #color=(#002EFC)
Install the downloaded application on your system like you install any other software for Windows simply double click on it and you will see the below interface. You just need to choose 'I accept the agreement' and click on the Next few times then click on Install.
Prettier is a code formatter that enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.(alert-success)
After the installation is done, click on the Settings icon from the lower-left corner and search for 'Default Formatter' setting and from the drop-down list choose the extension you have just installed as shown in the below image.
Now VS Code should use the Prettier extension to format your code but if you want your code to get formatted automatically then you can do one more set.
Search for the 'Format On Save' setting in the search bar and tick the check box as shown below so VS Code will automatically format your code whenever you save your file.
The next important setting that you need to search is 'Auto Save' and then set this option to 'onFocusChange'. It will automatically save your file when you go to another tab or you completely leave the window.
The last but very important extension which I personally found very useful is the Live Server extension. It launches the development local server with a live reload feature for static and dynamic web pages.
It means you don't need to refresh the web browser again and again to see the changes you have made in your code. You will find this so useful when you will start writing a lot of code for designing your web page.
To see your changes parallelly while writing the code, you can split your screen into two half as shown below.
So that's it. I hope you have done all the required changes and trust me this VS Code setup is going to increase your productivity a lot.
👉Support Us by Sharing our post with others if you really found this useful and also share your valuable feedback in the comment section below so we can work on them and provide you best 😊.(alert-success)
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.
Introduction to Web Development
![]() |
| Web Development |
If you are reading this article now then there is a good chance that this is your first introduction to any kind of Web Development. So before we start writing any kind of HTML code for designing the structure of a web page, it will be very useful if we get a basic introduction to Web Development.
This is just an overview of Web Development and we are not going to deep-dive into each sub-topics because we are going to learn about them in detail in upcoming blog posts. (alert-success)
Whenever you open your browser type the URL of the website you want to visit (ex: www.algolesson.com) and hit enter. You can see that the interface of the website gets loaded in your tab in just a fraction of a second. After the website gets loaded on your browser, you get options to perform many different kinds of activities, you can read the blog post, you can add your comments, or even share them on your social media.
Now let's understand how all these things are happening. So whenever you are trying to access any webpage, your browser sends a request to the web server where that particular webpage is hosted (stored) on the internet. When the server receives the request then it responds back to the browser (client) with all the files that make up the website and sends them back to the browser.
A browser can understand only three technologies, HTML, CSS, and JavaScript so whatever you see on your browser must be made up of only these three technologies. Once the browser receives these HTML, CSS, and JavaScript files from the server as a response then it will take the code and load the webpage you are trying to access.
Now as you already understand how a website loads on a browser let's understand how codes are written for such simple or complex websites.
Difference between front-end and back-end web development?
You can categorize any Web Development into two different types Front End Web Development and Backend Web Development.
The process of writing the HTML, CSS, and JavaScript code that any browser can understand and display is known as Front End Web Development.
When the files that make the website are simply stored on a web server and you receive them on your browser in the same condition without any transformation such websites are also called Static websites. ex: My Portfolio.(alert-passed)
But only Front End technologies are not enough to build big and complex websites like YouTube because if you visit such websites you will notice it keeps on changing every time you visit. You can notice that many new videos are getting uploaded each day, viewers are posting comments, and video suggestions that load on your browser are not the same for all other users.
So to make a big website like YouTube, you need a whole Application to keep running on the web server with a very Big Database to store all the information of that website. To build such a complex website developers write application code and keep running on web servers and for that developers use backend technologies like PHP, Java, nodejs, Python, etc.
These application codes take data from the database, process them, and generate files that will be sent to the browser based on the user's request. This entire process is called Backend Web Development because this processing is not visible to the user.Such websites which contain both frontend and backend technologies are also called Dynamic websites because the website is dynamically assembled each time when someone tries to visit the website. ex: YouTube (alert-passed)
(getButton) #text=(Setting up the Visual Studio Code Editor) #icon=(link) #color=(#2339bd)
👉Support Us by Sharing our HTML Course with others if you really found this course useful and also share your valuable feedback in the comment section below so we can work on them to improve our course 😊.(alert-success)
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.
Complete HTML Tutorial
Markup Language are those language which follow standard text encoding system with some set of symbols that decide the structure or your text document of a web page.(alert-passed)
| Introduction to Web Development. |
| HTML Tutorial |
|---|
| Introduction to HTML. |
| Elements in HTML. |
| Attributes in HTML. |
| Headings in HTML. |
| Paragraphs in HTML. |
| Styles in HTML. |
| Formatting in HTML. |
| Quotations in HTML. |
| Comments in HTML. |
| Colors in HTML. |
| Links in HTML. |
| Images in HTML. |
| Favicon in HTML. |
| Tables in HTML. |
| Lists in HTML. |
| Classes in HTML. |
| Id in HTML. |
| Iframes in HTML. |
| JavaScript in HTML. |
| File Paths in HTML. |
| HTML Head Explain. |
| HTML Layout Explain. |
| Responsive HTML Explain. |
| HTML Computer code. |
| Semantics in HTML. |
| Symbols in HTML. |
| Charset in HTML. |
| HTML URL Encode. |
| HTML Forms. |
| Forms in HTML. |
| Form Attributes in HTML. |
| Form Elements in HTML. |
| Input Types in HTML. |
| Input Attributes in HTML. |
| Input Form Attributes in HTML. |
| HTML Media. |
| Media Files in HTML |
| Video Files in HTML |
| Audio Files in HTML |
| Plug-ins in HTML |
| YouTube in HTML |
| Complete List of HTML Elements with Example. |
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.
Program for Next Smaller Element | C++ Solution.
Problem:
You are given an array of integers of size n. Your task is to print the next smaller element for each element present in the given array and if no smaller element is present for any element then print -1 for that element.
The Next Smaller Element for an array element (x) is the first smaller element on the right side of that element (x) in the array. If you reach the last element of the array in that case you cannot see any element on the right side so in that case print -1 if no Next Smaller Element is present.
You have to store all Next Smaller Elements in an array of n sizes and print them.
Input: arr = [ 2, 3, 1, 5, 9, 4 ]
Output: ans = [ 1, 1, -1, 4, 4, -1 ]
Explanation:
For 2, the next smaller element present on the right side of 2 in the array is 1.
For 3, the next smaller element present on the right side of 3 in the array is 1.
For 1, there is no next smaller element so you can print -1.
For 5, the next smaller element present on the right side of 5 in the array is 4.
For 9, the next smaller element present on the right side of 9 in the array is 4.
For 4, there is no element present on the right side of 4 so you can print -1. I hope that the problem statement is now clear to you, so let's start thinking about different approaches to solve this problem.
Approach 1: Using two nested loops.
Starting from the left side of the array, the outer loop will pick each element from the array one by one and the inner loop will check if any smaller element is present for the element picked by the outer loop on the right side of that element. If the smaller element is found then store that element in an array and if no smaller element is found then store -1.
#include <bits/stdc++.h> using namespace std; void nextSmallerElement(int arr[], int n, int ans[]) { for (int i = 0; i < n; i++) { int num = -1; for (int j = i + 1; j < n; j++) { if (arr[j] < arr[i]) { num = arr[j]; break; } } ans[i] = num; } } int main() { int arr[] = {2, 3, 1, 5, 9, 4}; int size = sizeof(arr) / sizeof(arr[0]); int ans[size]; nextSmallerElement(arr, size, ans); for (int i = 0; i < size; i++) { cout << ans[i] << " "; } }
Output:
1 1 -1 4 4 -1
- Time Complexity: O(n^2)
- Space Complexity: O(1)
Approach 2: Using Stack Data Strcuture.
As you can see that the above approach of solving the problem using two nested loop is not a good approach for solving this problem because it increases your time complexity to O(n^2). You can more efficiently solve the problem using Stack data structure and its property.
Create a Stack and push -1 initially and now -1 is present at the top of stack. Now approach the given array element from the right hand side and whenever you pick one element x , check the topmost element of the stack. If top element is smaller than the element x you just picked, store the topmost element of stack into your ans array and push the picked element x.
If you get a situation in which the topmost element is not smaller than element x start popping out elements from the stack until a topmost element smaller element than x. When you find that element, store that element into ans array and push the x into the stack.
#include <bits/stdc++.h> using namespace std; void nextSmallerElement(int arr[], int n, int ans[]) { stack<int> st; st.push(-1); for (int i = n - 1; i >= 0; i--) { int curr = arr[i]; while (st.top() >= curr) { st.pop(); } ans[i] = st.top(); st.push(curr); } } int main() { int arr[] = {2, 3, 1, 5, 9, 4}; int size = sizeof(arr) / sizeof(arr[0]); int ans[size]; nextSmallerElement(arr, size, ans); for (int i = 0; i < size; i++) { cout << ans[i] << " "; } }
Output:
1 1 -1 4 4 -1
- Time Complexity: O(n)
- Space Complexity: O(n)
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.
Stack STL Container in C++.
Stack is a Linear Data Structure that is based on LIFO (Last In First Out) principle and we also have a Stack container class in C++ STL (Standard Template Library) that is implemented based on the same LIFO principle.
When you use STL Stack, you don't have to worry about the implementation part of the stack operations like push(), pop(), top(), and empty() because in STL Stack all these operations are already provided in the form of a member function. You can directly use these member functions inside your program without thinking about the implementation part.
Important Stack STL member functions:
- push(): It is used to insert an element at the top end of the Stack.
- pop(): It is used to delete the topmost element of the Stack.
- top(): It returns the topmost element present in the Stack. This function just returns the value present on the top it does not remove that element from the Stack.
- empty(): It is a boolean function that will return true if Stack is empty else it will return false.
- size(): It is used to get the count of the number of elements present in the Stack.
Syntax: stack<datatype> stackname;
Example: C++ code for STL Stack.
#include <iostream> #include <stack> using namespace std; int main() { stack<int> st; st.push(50); st.push(40); st.push(30); st.push(20); st.push(10); cout << "Element present at the top: " << st.top() << endl; // delete top element of the stack st.pop(); cout << "Top element after deletion: " << st.top() << endl; if (st.empty()) { cout << "Stack is Empty." << endl; } else { cout << "Stack is not Empty." << endl; } cout << "Number of element present in stack " << st.size() << endl; }
Element present at the top: 10
Top element after deletion: 20
Stack is not Empty.
Number of element present in stack 4
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.
Stack Implementation using Linked List | C++ Code
You can implement the Stack data structure using a singly Linked List but you have to keep in mind that you have to perform all the Stack operations by following the LIFO (Last In First Out) principle. You also have to remember that all the Stack operations like push(), pop(), pee(), and isempty() must be performed under the constant time complexity of O(1).
Stack operations using Linked List:
To implement a stack using a linked list, you have to create one top pointer that will always point to the head of the linked list or you can say the topmost node of the stack. Because here, in this case, you are not just going to store the variable inside the stack instead you are going to store the node of the list. All your important operations like push and pop are going to perform from the beginning of the list or you can say at the head (top) of the list.
![]() |
| Push Operation into Stack |
push(): To perform the insert operation into the stack, you have to insert an element at the beginning of the list. When your head (top) is pointing to NULL it means your stack is empty so to insert an element into the stack you have to create one new node with that element and assign the address of this node to the head (top). And whenever you want to add one new element, you can perform insert at the beginning operation on the list.
![]() |
| Pop operation on Stack. |
pop(): To remove the top element of the stack, you can simply delete the first node of the list because it is the topmost element present in the stack and as you know that the head (top) always points to the beginning of the list. After deleting the first node, the head (top) will start pointing to the second node which is now the top element of the stack.
peek(): To get the information about the top element of the stack, you can simply return what value is present in the first node of the list which is pointed by the head (top) pointer. If the head (top) is pointing to NULL it means no element is present in the stack.
isempty(): It is very simple to know if the stack is empty or not, if your head contains a NULL value it means your stack is empty.
There is no condition when the stack gets full when you are implementing Stack using Linked List because the size of the Linked List can increase or decrease at runtime.
Example: C++ code for the Implementation of Stack using Singly Linked List.
#include <bits/stdc++.h> using namespace std; class ListNode { public: int data; ListNode *next; // constructor ListNode(int data) { this->data = data; this->next = NULL; } // destructor ~ListNode() { int value = this->data; if (this->next != NULL) { delete next; this->next = NULL; } cout << "Pop a Node with value " << value << endl; } }; // function to push element into stack void push(ListNode *&top, int num) { ListNode *temp = new ListNode(num); temp->next = top; top = temp; } // function to pop element from the stack void pop(ListNode *&top) { if (top == NULL) { cout << "Stack is Empty" << endl; } else { ListNode *temp = top; top = top->next; temp->next = NULL; delete temp; } } // function to check topmost element of stack int peek(ListNode *&top) { if (top == NULL) { cout << "Stack is Empty" << endl; return -1; } else { return top->data; } } // function to print all the element of stack void printStack(ListNode *&top) { ListNode *temp = top; while (temp != NULL) { cout << temp->data << endl; temp = temp->next; } } // function to check stack is empty or not bool isEmpty(ListNode *&top) { if (top == NULL) { return true; } return false; } int main() { ListNode *top = NULL; // push elements into stack push(top, 20); push(top, 30); push(top, 40); push(top, 50); cout << "Element present at the top of stack :"; cout << peek(top) << endl; pop(top); cout << "New top after deleting topmost element :"; cout << peek(top) << endl; cout << "Elements present in the stack :" << endl; printStack(top); if (isEmpty(top)) { cout << "Stack is Empty" << endl; } else { cout << "Stack is not Empty" << endl; } }
Element present at the top of stack :50
Pop a Node with value 50
New top after deleting topmost element :40
Elements present in the stack :
40
30
20
Stack is not Empty
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.
Stack Implementation using Array | C++ Code
The Stack data structure can be easily implemented using a 1D array. You can easily perform all the basic stack operations like push(), pop(), peek(), and isEmpty() in constant time O(1) without using any loop and by following the LIFO (Last In First Out) principle.
To implement all the stack operations, you need one fixed-size array and a very important variable name top that always points to the topmost element of the stack data structure. In your case, the top variable is going to hold the index of the top element of the stack.
- Initially, the top is initialized with a -1 value which means that your stack is empty and if you met a condition when (size of the array - top) is less than 1 then you can say your stack is full.
Stack operations using Array.
- Check if the stack is full or not. When (SIZE - 1 == top), "STACK is FULL" you cannot insert any further value to terminate the function.
- If (SIZE-1 is not equal to top), increment the top value by 1 (top++) and initialize arr[top] = value.
- Check if the stack is empty or not. When top == -1, "STACK IS EMPTY" there is no element present to delete so terminate the function.
- If top > -1, delete the top element by decreasing the top value by one. (top--).
- Check if top == -1, the stack is empty so there is no element present in the stack.
- If top > - 1, return the top value using arr[top].
- If top == -1, return true else return false.
Example: C++ code for Implementation of Stack using Array.
#include <bits/stdc++.h> using namespace std; class Stack { public: // integer type pointer int *arr; int top; int size; // behaviour Stack(int size) { this->size = size; // dynamically allocating memory arr = new int[size]; top = -1; } // function to push element in stack void push(int element) { if (size - 1 == top) { cout << "Stack OverFlow" << endl; } else { top++; arr[top] = element; } } // function to pop element in stack void pop() { if (top == -1) { cout << "Stack is Empty" << endl; } else { top--; } } // function to peek element in stack int peek() { if (top == -1) { cout << "stack is empty !!" << endl; return -1; } else { return arr[top]; } } // check if stack is empty or not. bool isEmpty() { if (top == -1) { return true; } else { return false; } } }; int main() { Stack s(5); s.push(20); s.push(30); s.push(40); s.push(50); cout << "Top Element: " << s.peek() << endl; // delete the top element of the stack which is now 50 s.pop(); // top element after deleting 50 cout << "Top Element: " << s.peek() << endl; if (s.isEmpty()) { cout << "Stack is Empty !!!" << endl; } else { cout << "Stack is not Empty !!!" << endl; } }
Output:
Top Element: 50 Top Element: 40 Stack is not Empty !!!
Implementation of Stack using Array is easy to use but it is not dynamic in nature so we can increase or decrease the size of Stack at runtime. To solve this problem, you can use Linked List for the implementation of Stack because as we know that the size of the Linked List data structure is not fixed.
I'm a full-time Software Developer with over 4 years of experience working at one of the world’s largest MNCs. Alongside my professional role, I run a news blog, WorkWithG.com, which focuses on Google tools, tutorials, and news. I'm passionate about breaking down complex topics and making learning accessible for everyone.













