LinkedList.h
class LinkedList;
class Node{
int data;
Node* next;
Node(int data , Node* next = (Node*)0);
friend class LinkedList;
};
class LinkedList{
Node* head;
Node* tail;
public:
LinkedList();
void add(int data);
int remove();
bool IsEmpty();
~LinkedList();
};
Linkedlist.cpp
#include "linkedlist.h"
Node::Node(int data, Node* next){
this->data = data;
this->next = next;
}
LinkedList::LinkedList(){
head = tail = (Node*)0;
}
LinkedList::~LinkedList(){
while(!IsEmpty()) remove();
}
LinkedList::add(int data){
Node* temp = new Node(data, tail);
if(tail){
tail->next = temp;
tail = temp;
}
else{
head = tail = temp;
}
}
bool LinkedList::IsEmpty(){
return !tail;
}
int LinkedList::remove(){
int data = 0;
return data;
}
I'm not sure this is correct !
Saturday, March 13, 2010
Queue's Operations from the C++ Standard Template Library
- bool empty()
- Returns True if the queue is empty, and False otherwise.
- T& front()
- Returns a reference to the value at the front of a non-empty queue. There is also a constant version of this function, const T& front().
- void pop()
- Removes the item at the front of a non-empty queue.
- void push(const T& foo)
- Inserts the argument foo at the back of the queue.
- size_type size()
- Returns the total number of elements in the queue.
va_list,va_start, va_arg, and va_end
va_list: Type to hold information about variable arguments
This type is used as a parameter for the macros defined in cstdarg to retrieve the additional arguments of a function.
Each compiler may implement this type in its own way. It is only intended to be used as the type for the object used as first argument for the va_start, va_arg and va_end macros.
va_start is in charge of initializing an object of this type, so that subsequent calls to va_arg with it retrieve the additional arguments passed to the function.
Before a function that has initialized a va_list object with va_start returns, the va_end shall be executed.
va_start: Initialize a variable argument list
void va_start ( va_list ap, paramN );
Initializes the object of type va_list passed as argument ap to hold the information needed to retrieve the additional arguments after parameter paramN with function va_arg.
A function that executes va_start, shall also execute va_end before it returns.
Parameters
ap
Object of type va_list that will hold the information needed to retrieve the additional arguments with va_arg.
paramN
Parameter name of the last named parameter in the function definition.
va_arg: Retrieve next argument
type va_arg ( va_list ap, type );
This macro expands to an expression that has the type type and the value of the next argument in the variable arguments list.
The next call to this macro will expand to the following argument in the same order as passed to the function.
Notice that va_arg cannot determine the actual type of the argument passed to the function, but uses whatever type is passed as the type macro argument as its type.
Notice also that va_arg does not determine either whether the retrieved argument is the last argument passed to the function (or even if it is an element past the end of that list). The function should be designed in such a way that the amount of parameters can be inferred in some way by the values of either the named parameters or the additional arguments already read.
Parameters
ap
Object of type va_list with information about the additional arguments an their retrieval state. This object shall have been initialized by an initial call to va_start before the first call to va_arg.
type
A type name. This type name is used as the type of the expression this macro expands to (i.e., its return type).
For a type expression to be suitable for its use with va_arg it must be such that when an asterisk (*) would be appended to its right the resulting expression would be a valid pointer type to a type object.
Return Value
Returns the next additional argument as an expression of type type.
va_end: End using variable argument list
void va_end ( va_list ap );
Performs the appropiate actions to facilitate a normal return by a function that has used the va_list object ap to retrieve its additional arguments.
This macro should be executed before the function returns whenever va_start has been previously used in that function.
Parameters
ap
va_list object previously initialized by va_start in the same function.
This type is used as a parameter for the macros defined in cstdarg to retrieve the additional arguments of a function.
Each compiler may implement this type in its own way. It is only intended to be used as the type for the object used as first argument for the va_start, va_arg and va_end macros.
va_start is in charge of initializing an object of this type, so that subsequent calls to va_arg with it retrieve the additional arguments passed to the function.
Before a function that has initialized a va_list object with va_start returns, the va_end shall be executed.
va_start: Initialize a variable argument list
void va_start ( va_list ap, paramN );
Initializes the object of type va_list passed as argument ap to hold the information needed to retrieve the additional arguments after parameter paramN with function va_arg.
A function that executes va_start, shall also execute va_end before it returns.
Parameters
ap
Object of type va_list that will hold the information needed to retrieve the additional arguments with va_arg.
paramN
Parameter name of the last named parameter in the function definition.
va_arg: Retrieve next argument
type va_arg ( va_list ap, type );
This macro expands to an expression that has the type type and the value of the next argument in the variable arguments list.
The next call to this macro will expand to the following argument in the same order as passed to the function.
Notice that va_arg cannot determine the actual type of the argument passed to the function, but uses whatever type is passed as the type macro argument as its type.
Notice also that va_arg does not determine either whether the retrieved argument is the last argument passed to the function (or even if it is an element past the end of that list). The function should be designed in such a way that the amount of parameters can be inferred in some way by the values of either the named parameters or the additional arguments already read.
Parameters
ap
Object of type va_list with information about the additional arguments an their retrieval state. This object shall have been initialized by an initial call to va_start before the first call to va_arg.
type
A type name. This type name is used as the type of the expression this macro expands to (i.e., its return type).
For a type expression to be suitable for its use with va_arg it must be such that when an asterisk (*) would be appended to its right the resulting expression would be a valid pointer type to a type object.
Return Value
Returns the next additional argument as an expression of type type.
va_end: End using variable argument list
void va_end ( va_list ap );
Performs the appropiate actions to facilitate a normal return by a function that has used the va_list object ap to retrieve its additional arguments.
This macro should be executed before the function returns whenever va_start has been previously used in that function.
Parameters
ap
va_list object previously initialized by va_start in the same function.
Structure VS union
Structure enables us treat a number of different variables stored at different in memory , a union enables us to treat the same space in memory as a number of different variables.
Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.
Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.
Subscribe to:
Posts (Atom)