Advertisement
FalconOS

Untitled

Jan 9th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C Compiler.
  4. Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. struct El {
  13. int info;
  14. struct El *next;
  15. };
  16.  
  17. typedef struct El ElementoLista;
  18.  
  19.  
  20.  
  21. ElementoLista* readList(ElementoLista **lista, int dis){
  22. ElementoLista* head;
  23. ElementoLista* aux= *lista;
  24. ElementoLista* elAdd;
  25. int now;
  26. int last;
  27.  
  28. scanf("%d", &now);
  29. if (dis>=0 && aux==NULL) {
  30. aux = malloc(sizeof(ElementoLista));
  31. head = aux;
  32. }
  33. last = now;
  34.  
  35. while(abs(now-last)<=dis){
  36. last = now;
  37. aux->info = last;
  38. scanf("%d", &now);
  39. if(abs(now-last)<=dis){
  40. elAdd = malloc(sizeof(ElementoLista));
  41. aux->next = elAdd;
  42. aux=aux->next;
  43. }
  44. }
  45.  
  46. aux->next=NULL;
  47.  
  48. return head;
  49.  
  50. };
  51.  
  52.  
  53.  
  54. void printList(ElementoLista *list){
  55. printf("(");
  56. while (list != NULL){
  57. printf("%d", list->info);
  58. list = list->next;
  59. }
  60. printf(")\n");
  61. }
  62.  
  63.  
  64.  
  65. int main(){
  66. ElementoLista *list = NULL;
  67. ElementoLista *list_aux = NULL;
  68. int boundis;
  69. int maxdis;
  70.  
  71. scanf("%d", &boundis);
  72.  
  73. list_aux = readList(&list, boundis);
  74.  
  75. printf("La lista bounded-%d e': \n",boundis);
  76.  
  77. if(list_aux != NULL){
  78. list = list_aux;
  79. list_aux = NULL;
  80. }
  81.  
  82. printList(list);
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement