Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- struct El {
- int info;
- struct El *next;
- };
- typedef struct El ElementoLista;
- ElementoLista* readList(ElementoLista **lista, int dis){
- ElementoLista* head;
- ElementoLista* aux= *lista;
- ElementoLista* elAdd;
- int now;
- int last;
- scanf("%d", &now);
- if (dis>=0 && aux==NULL) {
- aux = malloc(sizeof(ElementoLista));
- head = aux;
- }
- last = now;
- while(abs(now-last)<=dis){
- last = now;
- aux->info = last;
- scanf("%d", &now);
- if(abs(now-last)<=dis){
- elAdd = malloc(sizeof(ElementoLista));
- aux->next = elAdd;
- aux=aux->next;
- }
- }
- aux->next=NULL;
- return head;
- };
- void printList(ElementoLista *list){
- printf("(");
- while (list != NULL){
- printf("%d", list->info);
- list = list->next;
- }
- printf(")\n");
- }
- int main(){
- ElementoLista *list = NULL;
- ElementoLista *list_aux = NULL;
- int boundis;
- int maxdis;
- scanf("%d", &boundis);
- list_aux = readList(&list, boundis);
- printf("La lista bounded-%d e': \n",boundis);
- if(list_aux != NULL){
- list = list_aux;
- list_aux = NULL;
- }
- printList(list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement