An implementation of stack is similar to that of a Linked List. We will try to discuss the basic operations in a stack discussed in this post. MAIN OPERATIONS ON A STACK:- push( int ) :- Inserts a data into the stack pop :- Returns the topmost data from the stack AUXILIARY OPERATIONS ON A STACK int Top( ) :- returns the topmost element on the stack int Size( ) :- returns the total size of the stack int isStackEmpty( ) :- returns true if the stack is empty The…
nikoo28
nikoo28
a tech-savvy guy and a design buff... I was born with the love for exploring and want to do my best to give back to the community. I also love taking photos with my phone to capture moments in my life. It's my pleasure to have you here.
-
-
A stack is a linear data structure that maintains the order in which elements are added. It only has one point to add and remove data.
-
From Wikipedia: A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system). Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, “segmentation fault” being an example.…
-
Linked List
Find the merging point of 2 Linked Lists. Popularly called the Y-node problem.
by nikoo286 minutes readQuestion: You are given the head pointer to 2 single Linked Lists, and both of the lists converge at a certain point and then advance forward. We need to find the address of the node, at which both of the Linked Lists meet. Input: 4 -> 8 -> 15 -> 42 -> 99 16 -> 23 -> Output: 42 Suppose there are two single Linked Lists both of which intersect at some point and become a single Linked list. The head or start pointer of both the lists…
-
This is one of the method, not everyone is aware of in C. To generate a random number, C itself provides us a method srand(). We can use it in this way. NOTE: The function srand(time(NULL)) can only be called once in the program.
-
Many of us must have heard of the clause “Real Programmers code in C” and it is faster than any other language because “it is close to the machine“. What is so special about this language that makes it different from any other language. Let us try to explore this answer to some extent. There isn’t much that’s special about C. That’s one of the reasons why it’s fast. Newer languages which have support for garbage collection, dynamic typing and other facilities which make it easier for the programmer to…
-
Copying an entire Linked List, means allocating new memory and copying all the data to the new location. This requires traversing each node and copying its data to a new location, keeping the original data intact.
-
Question: Write a program to check if the given Linked List is a palindrome or not? Input: 1.> 4, 8, 15, 16, 23, 42 2.> 4, 8, 15, 16, 15, 8, 4 Output: 1.> IS NOT A PALINDROME 2.> IS A PALINDROME What is a Palindrome? According to Wikipedia, A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction. Thus, numbers like 121, 1331, 98711789 are palindromes. Similarly, Linked Lists can be…
-
Question: Given a Linked List, we need to find the middle of the list and print the number. Input: 4, 8, 15, 16, 23, 42, 99 Output: 16 This is a very basic question and is a part of a bigger problem. However, there are several approaches to solve the above problem. BRUTE-FORCE APPROACH In this approach, we count the number of nodes in the list for each of the node and see whether it is the middle. Time Complexity: O(n2) Space Complexity: O(1) MORE SIMPLIFIED APPROACH In this approach,…
-
Question: Write a program to reverse a Linked List in pairs. That means we should reverse the 1st and 2nd numbers, 3rd and 4th numbers and so on. Input: 4, 8, 15, 16, 23, 42 Output: 8, 4, 16, 15, 42, 23 The basic idea behind solving this problem is that we need to traverse the entire list and we need to keep on swapping the values of 2 adjacent nodes. Since we need to reverse the values in pairs, it is also clear that we need to move 2…