What is a Data Structure? A data structure is a way of organizing the data so that the data can be used efficiently. Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. For example, B-trees are particularly well-suited for the implementation of databases, while compiler implementations usually use hash tables to look up identifiers.

Source: Wiki Page. What are the various operations that can be performed on different Data Structures?

stack questions c++

How is an Array different from Linked List? What is Stack and where it can be used? Basic operations of the stack are: Push, Pop, Peek. What is a Queue, how it is different from the stack and how is it implemented?

stack questions c++

In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added. Converting between these notations: Click here. A linked list is a linear data structure like arrays where each element is a separate object. Each element that is node of a list is comprising of two items — the data and a reference to the next node.

Types of Linked List :. Can doubly linked be implemented using a single pointer variable in every node? Doubly linked list can be implemented using a single pointer. How to implement a stack using queue? A stack can be implemented using two queues. How to implement a queue using stack?

Subscribe to RSS

A queue can be implemented using two stacks. Let queue to be implemented be q and stacks used to implement q be stack1 and stack2. If inorder traversal of a binary tree is sorted, then the binary tree is BST. The idea is to simply do inorder traversal and while traversing keep track of previous key value. If current key value is greater, then continue, else return false. See A program to check if a binary tree is BST or not for more details. Which data structure is used for dictionary and spell checker?

Data Structure for Dictionary and Spell Checker? Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Writing code in comment? Please use ide. Skip to content. Related Articles.Ask Question.

Giunti al punto

Learn more… Top users Synonyms. Filter by. Sorted by. Tagged with. Apply filter. I have to do homework and there's my attempt to solve an exercise from the programming book. If you know what can be done better and I'm quite surprised by the results so wanted to ask if you see some mistakes in the way I measure Kirill Lykov 4 4 bronze badges. Time Conversion Problem. What am I doing wrong? I have given my best try along with the expected and my output below. Any optimisation Gautam 1 1 1 bronze badge.

I know using const SomeoneWithPassion 65 5 5 bronze badges. The trick is to trick the compiler into thinking that the r-value is an l-value by using a forwarding Cyrus 4 4 bronze badges. Roger Mas 3 1 1 bronze badge. Francis Cugler 3 3 silver badges 11 11 bronze badges. Memcpy function optimzation Here is my memcpy algorithm I've been working on Salmoncatt 31 1 1 bronze badge.

I have tried to implement LRU cache and the implementation that I have attached here works fine. However, I am not sure whether my code is in Tyler Durden 52 3 3 bronze badges.

Arrivo nebbiolo 2008

Optimize narrow phase contact detection for phyiscs simulation code I'm trying to optimize the narrow phase of the contact detection in my code.Ask Question. Learn more… Top users Synonyms. Filter by. Sorted by. Tagged with. Apply filter. Iacopo Olivo I have a UI, it has two "modes" one where it records and displays images and information about a recording device IE camera and another where it How to avoid cyclic dependency in UI application I'm developing an UI application where I ran into an issue with a cyclic dependency.

Sedi federcasa roma

Here is the simplified code, to explain the problem. I need to dynamically allocate Product objects by using Product's non-default constructor and store the objects in It is highly parallelizable.

Each worker can Dudly01 29 5 5 bronze badges. There are data Martin Ueding 1 1 gold badge 2 2 silver badges 7 7 bronze badges. How to write retry code when failure is inidicated by throwing an error? Assume I have an API that indicates failure by throwing an error because errors are not expected. In this situation, how should retry code be written? My first thought was to use something like this Jan Dorniak 2 2 silver badges 8 8 bronze badges.

When using templates we can have T be any type upon class instantiation.Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. It was originally designed as an extension to C and has a similar syntax, but it is now a completely different language.

Learn more. Ask Question. Filter by. Sorted by. Tagged with. Apply filter. The input file in the program is not working [closed] so I'm writing an assignment about writing a haiku and then storing the haiku into a text file. I have written the code and the output is working nicely but for my input whenever I try to run my code AdamMZ 5 2 2 bronze badges. TechnoCave 5 2 2 bronze badges. Reversing a vector using functions [closed] I'm trying to reverse a vector using functions but whenever I run the program it terminates and outputs nothing.

Can anyone please tell me what I am doing wrong? Harsh Sason 27 4 4 bronze badges. Python and am trying to make the interface between them more python friendly. More complex diamond problem instance. How to make it work with constant fields? Let us consider ordinary diamond problem but slightly improved. Now class A have constant fields. Beautiful Baguette Being 9. Why VisualBasic VB.Join Stack Overflow to learn, share knowledge, and build your career. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Instead 3 is propagating all the way to haha? What is the terminology of these two types: 3 propagates all the way vs some operation is successful.

Instead, the result of an assignment is the value that was assigned. In some cases, the compiler will give an error when you use an operator incorrectly. However, the compiler will just assume you know what you are doing if there is no error that it can find.

Because, when assignment happens, all expression in the right side of the operator needs to be evaluated, then result becomes assigned to variable in the left side of the operator.

stack questions c++

That is why hehe equals hahaand haha equals 3. Learn more. Asked yesterday. Active yesterday. Viewed times. To make things more meaningful, basically for the below two cases.

I somehow imagined them to be similar, right hand side first. So they are actually NOT similar? I know assignment is right associative. So haha is assigned with 3 first. Improve this question. What other languages uses "this operation was successful"?

Chhota english song

Add a comment. Active Oldest Votes. Improve this answer. Code-Apprentice Code-Apprentice Alvan Rahimli Alvan Rahimli 6 6 bronze badges. At the first line: A variable named "haha" is created.

At the second line: A variable named "hehe" is created 3 gets assigned to haha The value of haha is evaluated and assigned to hehe Advice: Always initialize your variable at creation. SuperNoob SuperNoob 79 6 6 bronze badges. New contributor. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.Describe stack operation. Stack is a data structure that follows Last in First out strategy. Stack Operations:- Push — Pushes inserts the element in the stack.

The location is specified by the pointer. Pop — Pulls removes the element out of the stack.

LeetCode 155. Min Stack (Algorithm Explained)

The location is specified by the pointer Swap: - the two top most elements of the stack can be swapped Peek: - Returns the top element on the stack but does not remove it from the stack Rotate:- the topmost n items can be moved on the stack in a rotating fashion A stack has a fixed location in the memory. When a data element is pushed in the stack, the pointer points to the current element Describe queue operation.

C++ - STACK Implementation using C++ Class with PUSH, POP, TRAVERSE Operations.

Queue is a data structure that follows First in First out strategy. Queue Operations: Push — Inserts the element in the queue at the end. Pop — removes the element out of the queue from the front Size — Returns the size of the queue Front — Returns the first element of the queue.

Empty — to find if the queue is empty. Discuss how to implement queue using stack. A queue can be implemented by using 2 stacks:- 1. An element is inserted in the queue by pushing it into stack 1 2.

An element is extracted from the queue by popping it from the stack 2 3.

Hindustan movie netflix

If the stack 2 is empty then all elements currently in stack 1 are transferred to stack 2 but in the reverse order 4. If the stack 2 is not empty just pop the value from stack 2. Explain stacks and queues in detail. A stack is a data structure based on the principle Last In First Out. Stack is container to hold nodes and has two operations - push and pop.

Push operation is to add nodes into the stack and pop operation is to delete nodes from the stack and returns the top most node. A queue is a data structure based on the principle First in First Out. The nodes are kept in an order. A node is inserted from the rear of the queue and a node is deleted from the front. The first element inserted in the first element first to delete.

Question - What are priority queues? A priority queue is essentially a list of items in which each item has associated with it a priority Items are inserted into a priority queue in any, arbitrary order. However, items are withdrawn from a priority queue in order of their priorities starting with the highest priority item first. Priority queues are often used in the implementation of algorithms Question - What is a circular singly linked list? In a circular singly linked list, the last node of the list is made to point to the first node.

This eases the traveling through the list. Data Structures Trees interview questions - freshers, experienced Data Structures Trees interview questions for freshers and experienced - In this series, we have covered all about Trees and answered the questions that might be asked during an interview. What is Service-Oriented Architecture? Why SOA? Services can be published, discovered and used in a technology neutralCode Review Stack Exchange is a question and answer site for peer programmer code reviews.

It only takes a minute to sign up. My questions are: - what could be generally done better here? Does it create any memory leaks? Is there a way to write it shorter? It is generally frowned upon to call new and delete directly, simply because doing it correctly is hard.

Your current Stack implements neither of those 5 operations correctly -- it doesn't implement them at all, and the default generated operations are buggy due to your use of a raw pointer. The best advice for resource handling, though, is to use the Rule of Zero : just delegate it to something that works! You don't want users of this library to be manually able to access top. Your current way of releasing memory is assuming that the user will pop on all elements; more of than that, it will not be the case.

Consider this:. No pop is called, and st object is deleted. All the allocations aren't deallocated, and you're leaking memory. In addition to Rish's good answer, here are some software engineering rather than coding remarks.

Show us that you organized the code properly by factoring out what you actually are presenting: The "library" part, consisting of two files: The header and the implementation, unless you decide to keep all functions inline which seems defensible in this case.

Use doxygen style comments to document your code. Good documentation focuses on the non-obvious. A function with a speaking name e. But you should document non-obvious parameters and return values, invariants, non-obvious side effects and generally any peculiarities.

In short, establish context. For anything but a toy project I would also really appreciate a module test. Such a test is essential for a library like this stack which will be used by "third parties" perhaps yourself in a different role. A comprehensive test takes on the role of a specification: As long as the users don't do anything that does not occur in the test, they can expect that a library upgrade does not introduce bugs into their software. If the test is comprehensive it will prevent most errors from reaching the users.

For open source projects tests are typically deployed together with the source code, so users can run them after they built their version. Typically there is limited time or interest for writing tests, so it should focus on problems. The following questions can help to identify spots worth testing:. Your linked-list implementation of a stack is well written in respect to you're being a learner.

Tiger beer origin

Since I am a "native" Java developer, I can better judge on the or similar Java Implementation of a Stack using generics. Sign up to join this community.

Stack and Queue C/C++ Programs

The best answers are voted up and rise to the top. Asked 9 months ago. Active 9 months ago. Viewed 2k times.

stack questions c++

Thank you in advance!