Autor Tema: meter en una funcion  (Leído 3848 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado tomario

  • PIC10
  • *
  • Mensajes: 22
meter en una funcion
« en: 31 de Diciembre de 2010, 07:52:58 »
hola en clase me han dado este codigo y tengo que meterlo en una funcion, cualquier ayuda que me puedan dar o como debo empezar, llevo dos dias y no he conseguido nada, gracias
Código: C
  1. #include <stdio.h>     
  2. #ifndef _LINKEDLIST_H_
  3. #define _LINKEDLIST_H_
  4. #ifndef _POLYGONSTRUCT_H_
  5. #define _POLYGONSTRUCT_H_
  6. #include <GL/gl.h>     
  7. #define MAXVERTS 32    
  8.  
  9.  
  10. typedef struct poly_struct {
  11.     int type;                   /* E.g., 0=SQUARE, 1=POLY, 2=RECT, ... */
  12.     GLint numVerts;             /* # of vertices in polygon */
  13.     GLdouble v[MAXVERTS][2];    /* Polygon's vertex array:       */
  14.                                 /* v[i][0] = vertex i's x-coord; */
  15.                                 /* v[i][1] = vertex i's y-coord  */
  16.     GLdouble center[2];         /* Polygon's "center" point, for use in */
  17.                                 /* rotating polygon                     */
  18.     GLdouble rot_angle;         /* Rotation angle for polygon (degrees) */
  19.     GLdouble rgb[3];            /* Polygon's color: 0.0=off, 1.0=max; */
  20.                                 /* rgb[0]=red, [1]=green, [2]=blue    */
  21. } Polygon;
  22. #endif
  23.  
  24.  
  25.  
  26. typedef struct polygon_list_struct {
  27.     Polygon p;
  28.     struct polygon_list_struct *next,   /* Pointers to next, prev polygons */
  29.                                *prev;   /* in the doubly-linked list */
  30. } Polygon_list_node;
  31.  
  32.  
  33. #endif
  34.  
  35. /*
  36.  * Global pointers for the linked list:
  37.  */
  38. Polygon_list_node *head = NULL, /* Pointer to the head of the list */
  39.                   *curr = NULL, /* Pointer to the currently selected node */
  40.                   *tail = NULL; /* Pointer to the tail of the list */
  41.  
  42. void InsertAfter(Polygon_list_node *item, Polygon_list_node *afterMe) {
  43.    /*
  44.     * Inserts *item after *afterMe in the linked list:
  45.     */
  46.     if (afterMe == NULL) {
  47.         if (head == NULL && tail == NULL) {     /* empty list */
  48.             head = tail = item;
  49.             item->prev = item->next = NULL;
  50.         }
  51.         else
  52.             fprintf(stderr,"InsertAfter: cannot insert after a NULL ptr\n");
  53.         return;
  54.     }
  55.     item->prev = afterMe;
  56.     if (afterMe == tail) {
  57.         tail = item;
  58.         item->next = NULL;
  59.     }
  60.     else {
  61.         item->next = afterMe->next;
  62.         item->next->prev = item;
  63.     }
  64.     afterMe->next = item;
  65. }
  66.  
  67. void InsertBefore(Polygon_list_node *item, Polygon_list_node *beforeMe) {
  68.    /*
  69.     * Inserts *item before *beforeMe in the linked list:
  70.     */
  71.     if (beforeMe == NULL) {
  72.         if (head == NULL && tail == NULL) {     /* empty list */
  73.             head = tail = item;
  74.             item->prev = item->next = NULL;
  75.         }
  76.         else
  77.             fprintf(stderr,"InsertBefore: cannot insert before a NULL ptr\n");
  78.         return;
  79.     }
  80.     item->next = beforeMe;
  81.     if (beforeMe == head) {
  82.         head = item;
  83.         item->prev = NULL;
  84.     }
  85.     else {
  86.         item->prev = beforeMe->prev;
  87.         item->prev->next = item;
  88.     }
  89.     beforeMe->prev = item;
  90. }
  91.  
  92. void RemoveItem(Polygon_list_node *item) {
  93.    /*
  94.     * Removes *item from the linked list (but doesn't free() it):
  95.     */
  96.     if (item == NULL)           /* Should print out an error message */
  97.         return;
  98.     if (item == head && item == tail) { /* Only one element in the list */
  99.         head = tail = NULL;
  100.     }
  101.     else if (item == head) {
  102.         item->next->prev = NULL;
  103.         head = item->next;
  104.     }
  105.     else if (item == tail) {
  106.         item->prev->next = NULL;
  107.         tail = item->prev;
  108.     }
  109.     else {
  110.         item->prev->next = item->next;
  111.         item->next->prev = item->prev;
  112.     }
  113.     item->prev = item->next = NULL;
  114. }

Desconectado tomario

  • PIC10
  • *
  • Mensajes: 22
Re: meter en una funcion
« Respuesta #1 en: 04 de Enero de 2011, 13:15:08 »
lo que necesito es hacer el main y en ese main llamar al resto de funciones.
si me pueden ayudar
gracias

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7918
Re: meter en una funcion
« Respuesta #2 en: 04 de Enero de 2011, 15:22:19 »
Pero el main es lo primero que deberias tener !! :shock: :shock:
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado fidodido18

  • PIC18
  • ****
  • Mensajes: 312
Re: meter en una funcion
« Respuesta #3 en: 05 de Enero de 2011, 12:02:07 »
te recomiendo que busques un buen libro de c++ o en internet encuentras muchos tutoriales...


 

anything