answersLogoWhite

0


Best Answer

queue is an abstract data type that which entities in a collection are kept in order, this makes the sense of fifo(first in first out).

stack is a container of the object which works on the principle of lifo(last in first out)

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

An example of a stack using arrays (vectors in C++):

#include<iostream>

#include<stack>

#include<vector>

int main()

{

std::stack<int, std::vector<int>> my_stack;

my_stack.push (42);

std::cout << my_stack.top() << std::endl;

my_stack.push (60);

std::cout << my_stack.top() << std::endl;

my_stack.pop();

my_stack.pop();

}

Note that if you do not supply a container, the default container for a stack<T> is a std::deque<T>. Often a vector uses less memory and is faster, however never assume this is always the case.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

The following demonstrates how to use a vector (a dynamic array in C++) to implement a stack. However, note that the C++ standard library already has a built-in stack, std::stack, that achieves exactly the same thing. There is no need to implement your own like this.

#include<iostream>

#include<vector>

template<typename T>

class stack

{

private:

std::vector<T> m_stack;

public:

void push(T value) { m_stack.push_back(value); }

void pop() { m_stack.pop_back(); }

const T& top () const { return m_stack.back(); }

};

int main()

{

stack<int> s;

std::cout << "Pushing onto stack..." << std::endl;

for (int v=0; v<10; ++v)

{

std::cout << v << std::endl;

s.push (v);

}

std::cout << "Popping from stack..." << std::endl;

for (int i=0; i<10; ++i)

{

std::cout << s.top() << std::endl;

s.pop ();

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

C language doesn't say anything about stacks and queues. You can implement those types, if you want, but first you have to choose a base-type, which defines the type of the stack- or queue-elements.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Stack is a special queue (or list), which has two main operations: push=add-to-the-beginning and pop=get/remove-from-the-beginning.

Note: Generic queues (or lists) have much more operations.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is stacks in data structure using c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the data structure which stores the multipole values?

No such thing exist in C but you can do this using structure data type and creating arrary of it object there after!!


MDU -1st semester subject codes?

data structure using c


What is the price of the book data structure using c and c plus plus by tanenbaum?

225 Rs. after discount........


What do you mean by non primitive data structure in C programming?

What do you mean by searching in data structure in C.?


Data structure algorithms using C?

array,linklist,queue,stack,tree,graph etc...


How do you implement queue using stack in c plus plus?

A queue in any language is a singly-linked list structure that permits new data to be inserted only at the end of a list while existing data can only be extracted from the beginning of the list. Queues are also known as a first in, first out (FIFO) structure. Unlike a standard singly-linked list, the list maintains a pointer to the last node as well as the first, in order to insert new data and extract existing data in constant time. Variations on the queue include the priority queue which permit data to be weighted, such that data with the greatest priority is promoted to the front of the queue, behind any existing data with the same or higher priority, using an insertion sort technique. Insertion is therefore achieved in linear time rather than constant time, however extraction is always in constant time.


C plus plus program using a stacks converting a postfix-infix?

Yes


Mini project on employee database using linked list on c language code?

mini project data structure


What is the structure and organization of data in a database called?

Data hierarchy is the structure and organization of data, which involves fields, records, and files. (c) Bidgoly MIS2.


What do you menat by a structre in c?

'structure' is also known as 'data-record' or 'compund data'


When class will be used and when structure will be used?

In class default members are private and in structure default members are public ,When ever you want to hide data from outside functions then you can use class.But in ANSI C we can hide data by using private access specifier.


How do you create modules in c language?

by using structure in c.........