0
#include <stdio.h>
#include <stdlib.h>
typedef struct ListElmt_{
int data;
struct ListElmt_ *next;
} ListElmt;
typedef struct List_ {
int size;
ListElmt *head;
ListElmt *tail;
} List;
List *list_init(){
List *list = (List *) malloc(sizeof(List));
list->size = 0;
list->head = NULL;
list->tail = NULL;
return list;
}
void insert(List *list,int num){
ListElmt *node = (ListElmt *) malloc(sizeof(ListElmt));
if(list->size == 0){
node->data = num;
node->next = NULL;
list->head = node;
list->tail = node;
}
else{
node->data = num;
node->next = NULL;
list->tail->next = node;
list->tail = node;
}
(list->size)++;
}
int *pop(List *list){
if(list == NULL){
printf("Lista vazia.\n");
return 0;
}
ListElmt *node = list->head;
list->head = node->next;
(list->size)--;
return node->data;
free(node);
}
ListElmt *atpos(List *list, int pos){
if(pos>=0 && pos<=list->size){
ListElmt *node = list->head;
int i;
for(i=0;i<pos;i++)
node = node->next;
return node;
}
//printf("Posicao invalida.\n");
}
int *removeatpos(List *list, int pos){
ListElmt *current = atpos(list,pos);
if(current!=NULL){
ListElmt *previous = atpos(list,pos-1);
previous->next = current->next;
return current->data;
free(current);
(list->size)--;
}
}
void progress(List *list, int i, int j){
if(list == NULL)
{
printf("Lista vazia.\n");
return;
}
int aux=0;
ListElmt *node = atpos(list,i-1);
ListElmt *previous = atpos(list,j);
while(node != previous){
node = node->next;
free(node->next);
}
}
void printList(List *list){
if(list == NULL)
{
printf("Lista vazia.\n");
return;
}
ListElmt *node = list->head;
while(node != NULL){
printf("%d ",node->data);
node = node->next;
}
}
int main(){
List *list = list_init();
insert(list,10);
insert(list,20);
insert(list,30);
insert(list,40);
insert(list,50);
insert(list,60);
insert(list,70);
//int num = pop(list);
int pos = 3,aux;
aux = pos-1;
int i=2,j=5;
//int num = removeatpos(list,pos-1);
progress(list,i-1,j-1);
printList(list);
return 0;
}
I’m having trouble with my job progress
, she would have to withdraw the numbers 20 30 40 50, but she’s not doing it this way.
Okay, thank you very much !
– Pedro Henrique Faria Teixeira