rendered paste bodymain()
{
struct NODE *head;
head=NULL;
menu(head);
end_procs(&head);
}
void pause()
{
char c;
printf("Πιέστε το πλήκτρο <Enter> για συνέχεια...\n");
c=getchar();
c=getchar();
}
/* εισάγει νεο στοιχείο και κόμβο στην λίστα */
void insert_new_node(struct NODE **head, struct NODE tmpnode)
{
struct NODE *newnode, *tmp;
if ((tmp=search(*head,tmpnode.code))!=NULL){
printf("Κόμβος με το συγκεκριμένο κωδικό υπάρχει ήδη...\n");
pause();
pre_insert_new_node(head);
}
newnode=(struct NODE *)malloc(sizeof tmpnode);
if (newnode==NULL){
printf("Δεν υπάρχει χώρος στην μνήμη...\n");
pause();
pre_insert_new_node(head);
}
*newnode=tmpnode;
newnode->next=NULL;
if (*head == NULL)
*head=newnode;
else
{
tmp=*head;
while (tmp->next!= NULL)
tmp=tmp->next;
tmp->next = newnode;
}
printf("Ο κομβος καταχωρήθηκε επιτυχώς!\n");
pause();
}
void pre_insert_new_node(struct NODE **head)
{
struct NODE tmp;
int flag;
printf(" __________________\n"
"| Εισαγωγή Κόμβου: |\n"
"|__________________|\n");
printf("Εισάγετε Κωδικό: "); scanf("%d",&tmp.code);
printf("Εισάγετε Λεκτικό: "); scanf("%s",&tmp.item);
insert_new_node(head,tmp);
}
/* κάνει αναζήτηση στην λίστα με βάση το κωδικό-μερος */
struct NODE *search(struct NODE *head, int code)
{
struct NODE *tmp;
if (head==NULL) return NULL;
tmp=head;
while (tmp->code!=code && tmp->next!=NULL)
tmp=tmp->next;
if (tmp->code==code) return tmp;
else return NULL;
}
void list_print(struct NODE *head)
{
int i;
struct NODE *tmp;
if(head==NULL) printf("den\n");
else
{
tmp=head;
while (tmp!=NULL)
{
if (i==0)
printf(" ___________________________________________"
"| Node code | Node include | Next node code |"
"|___________|______________|________________|");
else if (i==31) i=0;
i++;
printf("%d | %s | %d\n",head->code,head->item,head->next);
tmp=tmp->next;
}
}
pause();
}
/* menu: υπάρχει για να δυσκολέυει τις ζωές ὸλων μας */
void menu(struct NODE *head)
{
int sel, code;
do
{
system("clear");
printf(" ______________________________________________\n"
" | M E N U |\n"
" |______________________________________________|\n"
" | |\n"
" |[1] Εισαγωγή κόμβου... |\n"
" |[2] Αναζήτηση κόμβου με βάση το κωδικό του... |\n"
" |[3] Διόρθωση λεκτικού μέρους του κόμβου... |\n"
" |[4] Διόρθωση κωδικού μέρους του κόμβου... |\n"
" |[5] Διαγραφή κόμβου... |\n"
" |[6] Εμφάνιση της λίστας... |\n"
" |[7] Γράψιμο της λίστα σε αρχείο... |\n"
" |[8] Διέβασμα της λίστα απο αρχείο... |\n"
" |[9] Έξοδος απο το πρόγραμμα και σχόλια... |\n"
" |______________________________________________|\n\n"
" Πληκτρολογείστε κωδικό αριθμό της επιλογής σας και πιέστε το ENTER : ");
scanf("%d",&sel);
switch (sel)
{
case 1: pre_insert_new_node(&head); break;
case 2: search_from_menu(head,code); break;
case 3: correct_lecture(head); break;
case 4: correct_code(head); break;
case 5: delete_node(head); break;
case 6: list_print(head); break;
case 7: write_list_in_file(head); break;
case 8: read_list_from_file(head); break;
case 9: exit_from_menu(); break;
}
}
while (sel != 9);
}