linkedin github youtube instagram
#include <stdio.h>
#include <stdlib.h>

struct n{
	int x;
	struct n *next;
};

typedef n node;


node * appendElement(node * r,int val,node * last = NULL){
	node * iter;
	if(last != NULL) iter = last;
	else iter = r;
	
	while(1){
		if(iter->next == NULL) {
			iter->next = (node *) malloc(sizeof(node*));
			iter->next->next = NULL;
			iter->x = val;
			return iter;
		}
		iter = iter->next;
	}
}

void showList(node * r);

int main(){
	char control;
	int val;
	node *root;
	node *last = NULL;
	root = (node*) malloc(sizeof(node*));
	root->next = NULL;
	while(1){
		printf("\nBir sayi giriniz : ");
		scanf("%d",&val);
		last = appendElement(root,val,last);
		printf("\nDevam etmek ister misiniz (y/n) : ");
		scanf(" %c",&control);
		if(control != 'y') break;	
	}
	showList(root);	
}




void showList(node *r){
	node * iter;
	iter = r;
	int i = 1;
	while(iter->next != NULL){
		printf("%d.eleman %d\n",i,iter->x);
		iter = iter->next;
		i++;
	}
}