duplamente encadeada

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #include <stdlib.h> typedef struct estru { int num; struct estru *prev; struct estru *next; } lista; int mostraListainvert(lista *p, lista *begin) { while(p != begin) { printf(" %d ->", p->num); p = p->prev; } printf(" %d ->fim da lista\n\n", p->num); } void mostraLista(lista *begin) { lista *p = begin; printf("\n\n"); p = begin; while(p->next != begin) { printf(" %d ->", p->num); p = p->next; } printf(" %d ->fim da lista\n\n", p->num); } int main(void) { lista *p, *q, *begin=NULL, *begin2=NULL; int num, rem; scanf("%d", &num); printf("Tamanho da lista: %d", num); for(int i = 1; i <= num; i++) { p = (lista *) malloc(sizeof(lista)); scanf("%d", &p->num); if(begin==NULL) { begin = p; p->prev = p; p->next = p; } else { p->prev = q; p->next = begin; begin->prev = p; q->next = p; } q = p; printf("\nNó %d: %d", i, p->num); } mostraLista(begin); scanf("%d", &rem); printf("Nó a ser deletado: %d", rem); p = begin; for(int i = 1; i <= num; i++) { p = p->next; if(i == rem) { } } free(p); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines