|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



LINKED LIST

Linked List:



OpenVera supports Linked list.It also supports object based Linked list also.First declare the Linked list type and then take instances of it.OpenVera has many methodes to operate on this instancess.

List Definitions:

List :- A list is a doubly linked list, where every element has a predecessor and successor. It is a sequence that supports both forward and backward traversal, as well as amortized constant time insertion and removal of elements at the beginning, end, or middle.

Container :- A container is a collection of objects of the same type .Containers are objects that contain and manage other objects and provide iterators that allow the contained objects (elements) to be addressed. A container has methods for accessing its elements. Every container has an associated iterator type that can be used to iterate through the containerĀ“s elements.

Cterator :- Iterators provide the interface to containers. They also provide a means to traverse the container elements. Iterators are pointers to nodes within a list. If an iterator points to an object in a range of objects and the iterator is incremented, the iterator then points to the next object in the range.

The following procedure shouws how to creat List and use it:
1)Creat List:
MakeVeraList(data_type);

2)Declare Lists
VeraList_data_type list1;

3)Declare List Iterators
VeraListIterator_data_type iterator1;



List Methods:



size() : The size() method returns the number of elements in the list container.
empty() :The empty() method returns 1 if the number of elements in the list container is 0:
clear() :The clear() method removes all the elements of the specified list.
erase() :The erase() method removes the indicated element.
push_front():The push_front() method inserts data at the front of the list.
push_back() :The push_back() method inserts data at the end of the list.
pop_front() :The pop_front() method removes the first element of the list.
pop_back() :The pop_back() method removes the last element of the list.
insert() :The insert() method inserts data before the indicated position:
insert_range() :The insert_range() method inserts elements in a given range before the indicated position.
start() :The start() method returns an iterator pointing to the first element in the list.
finish() :The finish() method returns an iterator pointing to the very end of the list.
next() :The next() method moves the iterator so that it points to the next item in the list.
prev() :The prev() method moves the iterator so that it points to the previous item in the list.
eq() :The eq() method compares two iterators.
neq() :The neq() method compares two iterators.
front() :The front() method returns the first element in the list.
back() :The back() method returns the last element in the list.
data() :The data() method returns the data stored at a particular location:



EXAMPLE:Linked list
#include <VeraListProgram.vrh>
#include <ListMacros.vrh>

MakeVeraList(integer);
program main{

VeraList_integer List1;
VeraListIterator_integer itor;

List1 = new();
printf (" size of list is %d \n",List1.size());
List1.push_back(10);
List1.push_front(22);
printf (" size of list is %d \n",List1.size());
printf (" poping from list : %d \n",List1.front());
printf (" poping from list : %d \n",List1.front());
List1.pop_front();
List1.pop_front();
printf (" size of list is %d \n",List1.size());
List1.push_back(5);
List1.push_back(55);
List1.push_back(555);
List1.push_back(5555);
printf (" size of list is %d \n",List1.size());

itor = List1.start();
printf (" startn of list %d \n",itor.data());
itor.next();
printf (" second element of list is %d \n",itor.data());
itor.next();
printf (" third element of list is %d \n",itor.data());
itor.next();
printf (" fourth element of list is %d \n",itor.data());

itor = List1.erase(itor);
printf (" after erasing element,the itor element of list is %d \n",itor.data());
itor.prev();
printf(" prevoious element is %d \n",itor.data());

printf (" END OF PROGRAM\n");
}


RESULTS:

size of list is 0
size of list is 2
poping from list : 22
poping from list : 22
size of list is 0
size of list is 4
startn of list 5
second element of list is 55
third element of list is 555
fourth element of list is 5555
after erasing element,the itor element of list is x
prevoious element is 555
END OF PROGRAM

Index
Introduction
Data Types
Linked List
Operators Part 1
Operators Part 2
Operators Part 3
Operator Precedence
Control Statements
Procedures And Methods
Interprocess
Fork Join
Shadow Variables
Fork Join Control
Wait Var
Event Sync
Event Trigger
Semaphore
Regions
Mailbox
Timeouts
Oop
Casting
Randomization
Randomization Methods
Constraint Block
Constraint Expression
Variable Ordaring
Aop
Predefined Methods
String Methods
Queue Methods
Dut Communication
Functional Coverage

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer