Вы находитесь на странице: 1из 8

TECHNICAL UNIVERSITY OF MANAB FACULTY OF INFORMATICS SCIENCE ENGINEERING DEGREE IN COMPUTER SYSTEMS DATA STRUCTURE TASK # 7.

SPECIAL TYPES OF SIMPLE LISTS (BATTERIES AND QUEUES)

AUTHOR:
PAREDES BRAVO JONATHAN ANDRES

PROFESSOR:
MR. CHRISTIAN TORRES.

LEVEL:
SECOND "C"

PERIOD:
SEPTEMBER 2012 - FEBRUARY 2013

FACULTAD DE CIENCIAS INFORMTICAS

Mission:
Be a unit with high academic prestige, efficiency, transparency and quality in education, organized in their activities, protagonists of regional and national progress.

Vision:
Form efficient professionals and innovators in the field of computer science, giving answers to the needs of society with honesty, fairness and solidarity, raising their standard of living.

TECHNICAL UNIVERSITY OF MANAB

Mission:
Train academics, scientists and responsible professionals, humanist, ethical and supportive, committed to the objectives of national development, which will contribute to the solution of the problems of the country as university teaching with research, able to generate and apply new knowledge, fostering the promotion and dissemination of knowledge and cultures, provided for in the Constitution of the Republic of Ecuador.

Vision:
Be referent, leader and university institution of higher education in Ecuador, by promoting the creation, development, transmission and dissemination of science, technique and culture, social recognition and projection, regionally and globally.

LIST DEFINITION OPEN SIMPLE


The simplest form of dynamic structure is the open list. In this way the nodes are organized so that each points to the next, and last no points to nothing, i.e. the next node pointer is NULL. A special node exists in open lists: the first. We normally say that our list is a pointer to the first node and that node will call the head of the list. That's because by that single pointer we can access the entire list. When the pointer that we use to access the list is NULL, we say that the list is empty. The node typical to build lists has this form: struct node \ { } int dato; struct node * next; }; In the example, each item in the list contains only data of type integer, but in practice there is no limit in terms of the complexity of the data to be stored.
Type declarations to handle lists in C

Normally defines several types that facilitate the management of the lists, in C, the Declaration of types can have a form similar to this: typedef struct _node \ { } int dato; struct _node * next; } tipoNodo; typedef tipoNodo * pNodo; typedef tipoNodo * list; tipoNodo is the type for declaring nodes, obviously. pNodo is the type for declaring pointers to a node. List is the type to declare lists, as you can see, a list and a pointer to a node are the same thing. In reality, any pointer to a node is a list whose first element is the targeted node.

Linked list

It is very important that our program never lose the value of the pointer to the first element, since if there is no copy of that value, and is lost, it will be impossible to access the node and we will not release the memory space that occupies.

LIST DEFINITION CIRCULAR SIMPLE


A circular list is a linear list in which the last node to the first tip. The circular lists prevent exceptions in the operations carried out on them. There are no special cases, each node always has a previous and a next one. In some circular lists a special header, that node is added mode prevents the single possible exception, in that the list is empty. The typical node is the same as for build open lists: structnode \ { } intdato; structnode * next; };
Type declarations to handle circular lists in C

The types that we normally define to handle closed lists are the same for handling open lists: typedef struct _ node \ { } int dato; struct _ node * next; } tipoNodo; typedef tipoNodo * pNodo; typedef tipoNodo * list; tipoNodo is the type for declaring nodes, obviously. pNodo is the type for declaring pointers to a node.

List is the type to declare lists, both open as circular. In the case of the circular, you will point to any node in the list.

Circular list

While the circular lists simplify the operations on them, they also introduce some complications. For example, in a search process, it is not so easy to terminate the search when the searched item does not exist. For this reason usually highlight a node in particular, which does not have to be always the same. Any node can fulfill that purpose, and may vary during the execution of the program. Another alternative that is often used, and in a way that simplifies the use of circular lists is to create a special node of will make the header node function. In this way, the list is never empty, and almost all special cases are deleted.

THE OPERATIONS THAT YOU CAN PERFORM ON A LINKED LIST ARE THE FOLLOWING:
Tour. This operation consists of visiting each of the nodes that form the list. To scroll through all the nodes in the list, begins with the first, takes the value of the field League to advance to the second node, the field League of this node will give us the address of the third node, and so on. void traverse(struct list * ml) { If(ml! =?) { printf("\nElemento of the list: % d", ml - > data); travel(ml - > GIS); } } Inclusion. This operation consists of adding a new node to the list. Three cases can be considered for this operation: o Insert a node at the beginning.

Insert a node before or after certain node. o Insert a node at the end. 1. Create node to insert void Insert(Tlista & l, Tdato d) { Tlistadata; data= new (Tnodo); If(data == NULL) { cout < < 'ERROR'; } else { data- > data = d; data- > sig = NULL; 2. If the list is empty we introduce at the beginning: If(l == NULL) { l= data; } 3 If it is not empty, we check whether to add at the beginning: If(l.dato > d) { data- > sig = l; l= data; } Deleted. The erase operation is to remove a node from the list, redefining the leagues that correspond. Four cases may occur: o Delete the first node. o Remove the last node. o Deleting a node with some information. o Delete the node upstream or downstream from the certain node with information. If(l - > data == d) { ptr= l; l= l - > sig; delete(ptr); }
o

/ * We create two auxiliary pointers one that examines the current position and another indicating the previous position * / Pact= l - > sig; Pant= l; / * We loop through the list looking for the node to be deleted * / while((pact!= NULL) & & ) (pact->dato!= d)) { screen = pact; Pact = pact - > GIS; } / * Once found the position to delete the node * / If(pact! = NULL) { Pant-> sig = pact - > sig; delete(pact); } Search. This operation consists of visiting each of the nodes, taking to the field League as a pointer to the next node to visit.

Вам также может понравиться