Tugas Linked List
March13
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable: 4996) //menggunakan visual studio 2013
/*Created by
Alvin Oktavianus
1701293004
32PPT*/
struct tnode{
int x;
struct tnode *next;
};
struct tnode *head = NULL, *connector = NULL;
int main(){
int a, cout=0;
do{
system("cls");
connector = head;
if (connector != NULL){
while (connector->next != NULL){
printf("%d ", connector->x);
if (a > 0 || (a + 1) < 10){
printf("-> ");
}
connector = connector->next;
}
printf("%d", connector->x);
}
printf("\n");
if (cout != 10){
printf("input data : ");
scanf("%d", &a); fflush(stdin);
}
if (cout == 0){
head = (struct tnode*)malloc(sizeof(struct tnode));
head->next = NULL;
head->x = a;
connector = head;
}
else{
connector->next = (struct tnode*)malloc(sizeof(struct tnode));
connector = connector->next;
connector->next = NULL;
connector->x = a;
}
cout++;
} while (cout < 11);
printf("\n\n");
system("PAUSE");
return 0;
}