Vote count: 0
I want put value in linked list. But I have a problem, becouse I want get this: 123 but I get this 123 123 123 . . to infinity. What I doing wrong ?
#include<stdio.h>
#include<stdlib.h>
struct lista{
int data;
struct lista *next;
struct lista *prev;
};
struct lista *push(struct lista *head, struct lista *x){
x->next = head;
x->prev = NULL;
if(head!=NULL)
head->prev=x;
return x;
}
void show(struct lista *head){
while(head!=NULL){
printf("%d\n", head->data);
}
head = head->next;
}
int main(){
struct lista *head = NULL, *x = NULL;
x = (struct lista*)malloc(sizeof(struct lista));
x->data = 123;
head = push(head, x);
show(head);
return 0;
}
asked 15 secs ago
to much value element in linked list C/C++
Aucun commentaire:
Enregistrer un commentaire