answersLogoWhite

0


Best Answer

No, because C does not support the concept of template functions. Template functions only exist in C++, never in C.

User Avatar

Wiki User

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

Wiki User

9y ago

C is not an object oriented programming language so has no ADTs let alone template functions.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How you describe operations of stack ADT using c template functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

A stack class template in C?

I didnt get exactly what do you mean by stack class template, but this is one which implements a stack! and also shows how to implement it with templates http://thetechnofreaks.com/2011/10/26/4-creating-a-stack/#ixzz1bvq2V1Ws


Design an algorithm to show the different operations on a stack?

Design an algorithm to show the different operations on a stack?


Describe the output i.e. the sequences of numbers removed from the stack due to the following series of stack operations push6 push0 pop push5 push3 pop pop?

0 3 5


What is time complexity of stack?

All major queue operations (push, pop and front) are constant time operations.


What is stack define the operations of stack?

In modern computer languages, the stack is usually implemented with more operations than just "push" and "pop". The length of a stack can often be returned as a parameter. Another helper operation top (also known as peek and peak) can return the current top element of the stack without removing it from the stack. This section gives pseudocode for adding or removing nodes from a stack, as well as the length and top functions. Throughout we will use null to refer to an end-of-list marker or sentinel value, which may be implemented in a number of ways using pointers. In modern computer languages, the stack is usually implemented with more operations than just "push" and "pop". The length of a stack can often be returned as a parameter. Another helper operation top[1] (also known as peek and peak) can return the current top element of the stack without removing it from the stack. This section gives pseudocode for adding or removing nodes from a stack, as well as the length and top functions. Throughout we will use null to refer to an end-of-list marker or sentinel value, which may be implemented in a number of ways using pointers. record Node { data // The data being stored in the node next // A reference to the next node; null for last node } record Stack { Node stackPointer // points to the 'top' node; null for an empty stack } function push(Stack stack, Element element) { // push element onto stack new(newNode) // Allocate memory to hold new node newNode.data := element newNode.next := stack.stackPointer stack.stackPointer := newNode } function pop(Stack stack) { // increase the stack pointer and return 'top' node // You could check if stack.stackPointer is null here. // If so, you may wish to error, citing the stack underflow. node := stack.stackPointer stack.stackPointer := node.next element := node.data return element } function top(Stack stack) { // return 'top' node return stack.stackPointer.data } function length(Stack stack) { // return the amount of nodes in the stack length := 0 node := stack.stackPointer while node not null { length := length + 1 node := node.next } return length } As you can see, these functions pass the stack and the data elements as parameters and return values, not the data nodes that, in this implementation, include pointers. A stack may also be implemented as a linear section of memory (i.e. an array), in which case the function headers would not change, just the internals of the functions. Implementation A typical storage requirement for a stack of n elements is O(n). The typical time requirement of O(1) operations is also easy to satisfy with a dynamic array or (singly) linked list implementation. C++'s Standard Template Library provides a "stack" templated class which is restricted to only push/pop operations. Java's library contains a Stack class that is a specialization of Vector. This could be considered a design flaw because the inherited get() method from Vector ignores the LIFO constraint of the Stack. Here is a simple example of a stack with the operations described above (but no error checking) in Python. class Stack(object): def __init__(self): self.stack_pointer = None def push(self, element): self.stack_pointer = Node(element, self.stack_pointer) def pop(self): e = self.stack_pointer.element self.stack_pointer = self.stack_pointer.next return e def peek(self): return self.stack_pointer.element def __len__(self): i = 0 sp = self.stack_pointer while sp: i += 1 sp = sp.next return i class Node(object): def __init__(self, element=None, next=None): self.element = element self.next = next if __name__ == '__main__': # small use example s = Stack() [s.push(i) for i in xrange(10)] print [s.pop() for i in xrange(len(s))] The above is admittedly redundant as Python supports the 'pop' and 'append' functions to lists.

Related questions

A stack class template in C?

I didnt get exactly what do you mean by stack class template, but this is one which implements a stack! and also shows how to implement it with templates http://thetechnofreaks.com/2011/10/26/4-creating-a-stack/#ixzz1bvq2V1Ws


Design an algorithm to show the different operations on a stack?

Design an algorithm to show the different operations on a stack?


Describe the output i.e. the sequences of numbers removed from the stack due to the following series of stack operations push6 push0 pop push5 push3 pop pop?

0 3 5


How do you refresh stack using library functions in C programming?

What do you mean by stack-refreshing? Anyway, there are no stack handling functions in the standard C library.


What are the stack operation?

there are two operations you can do with a STACK one is PUSH operation and the other is POP operation


What is interface stack?

The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top.


What is time complexity of stack?

All major queue operations (push, pop and front) are constant time operations.


What is stack define the operations of stack?

In modern computer languages, the stack is usually implemented with more operations than just "push" and "pop". The length of a stack can often be returned as a parameter. Another helper operation top (also known as peek and peak) can return the current top element of the stack without removing it from the stack. This section gives pseudocode for adding or removing nodes from a stack, as well as the length and top functions. Throughout we will use null to refer to an end-of-list marker or sentinel value, which may be implemented in a number of ways using pointers. In modern computer languages, the stack is usually implemented with more operations than just "push" and "pop". The length of a stack can often be returned as a parameter. Another helper operation top[1] (also known as peek and peak) can return the current top element of the stack without removing it from the stack. This section gives pseudocode for adding or removing nodes from a stack, as well as the length and top functions. Throughout we will use null to refer to an end-of-list marker or sentinel value, which may be implemented in a number of ways using pointers. record Node { data // The data being stored in the node next // A reference to the next node; null for last node } record Stack { Node stackPointer // points to the 'top' node; null for an empty stack } function push(Stack stack, Element element) { // push element onto stack new(newNode) // Allocate memory to hold new node newNode.data := element newNode.next := stack.stackPointer stack.stackPointer := newNode } function pop(Stack stack) { // increase the stack pointer and return 'top' node // You could check if stack.stackPointer is null here. // If so, you may wish to error, citing the stack underflow. node := stack.stackPointer stack.stackPointer := node.next element := node.data return element } function top(Stack stack) { // return 'top' node return stack.stackPointer.data } function length(Stack stack) { // return the amount of nodes in the stack length := 0 node := stack.stackPointer while node not null { length := length + 1 node := node.next } return length } As you can see, these functions pass the stack and the data elements as parameters and return values, not the data nodes that, in this implementation, include pointers. A stack may also be implemented as a linear section of memory (i.e. an array), in which case the function headers would not change, just the internals of the functions. Implementation A typical storage requirement for a stack of n elements is O(n). The typical time requirement of O(1) operations is also easy to satisfy with a dynamic array or (singly) linked list implementation. C++'s Standard Template Library provides a "stack" templated class which is restricted to only push/pop operations. Java's library contains a Stack class that is a specialization of Vector. This could be considered a design flaw because the inherited get() method from Vector ignores the LIFO constraint of the Stack. Here is a simple example of a stack with the operations described above (but no error checking) in Python. class Stack(object): def __init__(self): self.stack_pointer = None def push(self, element): self.stack_pointer = Node(element, self.stack_pointer) def pop(self): e = self.stack_pointer.element self.stack_pointer = self.stack_pointer.next return e def peek(self): return self.stack_pointer.element def __len__(self): i = 0 sp = self.stack_pointer while sp: i += 1 sp = sp.next return i class Node(object): def __init__(self, element=None, next=None): self.element = element self.next = next if __name__ == '__main__': # small use example s = Stack() [s.push(i) for i in xrange(10)] print [s.pop() for i in xrange(len(s))] The above is admittedly redundant as Python supports the 'pop' and 'append' functions to lists.


What is the most common method for illustrating the operations of a networking stack?

The OSI Model


Can you use sp as offset address holder with cs?

SP is the stack pointer and can be used in the stack operations. It cannot be used for fetching the instruction


What is a stack and how do you represent a stack in computer memory also discuss basic operation performed on a stack?

A stack is an abstraction of First-in-last-out, or the last in first out. The basic operations (may bear different names) Push or Add Pop or Next


Design the stack with constructor?

The standard template library (STL) already includes a stack container. There is no need to develop your own. If you need to see the implementation details, consult the C++ ISO standard 23.6.5.2.