Compare commits
No commits in common. "7bc6a62777f278fe8e0354e64535840f03bb1dde" and "47f8fc2341fa6ed8035f8ba69506b4a3a3c544ba" have entirely different histories.
7bc6a62777
...
47f8fc2341
BIN
tests/linkedlist
BIN
tests/linkedlist
Binary file not shown.
@ -1,73 +0,0 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
struct node {
|
||||
int data;
|
||||
struct node *next;
|
||||
};
|
||||
|
||||
struct node *head = NULL;
|
||||
void add_first(int);
|
||||
void add_last(int);
|
||||
void traverse();
|
||||
void remove_first();
|
||||
void remove_last();
|
||||
int count = 0;
|
||||
void display_menu();
|
||||
|
||||
int main(void) {
|
||||
printf("Welcome!\n");
|
||||
|
||||
int selected, data;
|
||||
|
||||
while (1) {
|
||||
if (count == 100) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
// show menu
|
||||
display_menu();
|
||||
}
|
||||
|
||||
printf("\nGoodbye!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void display_menu() {
|
||||
|
||||
printf("1. Add first element\n");
|
||||
printf("2. Add last element\n");
|
||||
printf("3. Traverse element\n");
|
||||
printf("4. Remove first element\n");
|
||||
printf("5. Remove last element\n");
|
||||
|
||||
}
|
||||
|
||||
void add_first(int element) {
|
||||
// init node
|
||||
struct node *node;
|
||||
|
||||
// allocate the node for linkedlist
|
||||
node = (struct node*)malloc(sizeof(struct node));
|
||||
|
||||
// add the data into node
|
||||
node->data = element;
|
||||
|
||||
// count the nodes, that added into data
|
||||
count++;
|
||||
|
||||
// check the head, if null put the data into it
|
||||
if (head == NULL) {
|
||||
// replace the node into head
|
||||
head = node;
|
||||
|
||||
// set the next of head into null
|
||||
head->next = NULL;
|
||||
|
||||
// return or end this process
|
||||
return;
|
||||
}
|
||||
|
||||
node->next = head;
|
||||
head = node;
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm -r work1
|
||||
|
||||
gcc work1.c -o work1 && ./work1
|
||||
gcc work1.c -o work1
|
||||
./work1
|
@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm -r linkedlist
|
||||
|
||||
gcc linkedlist.c -o linkedlist
|
||||
|
||||
./linkedlist
|
14
tests/util.c
14
tests/util.c
@ -1,14 +0,0 @@
|
||||
#include "stdio.h"
|
||||
|
||||
void print(char *text) {
|
||||
printf(text);
|
||||
}
|
||||
|
||||
void println(char *text) {
|
||||
newline();
|
||||
print(text);
|
||||
}
|
||||
|
||||
void newline() {
|
||||
printf("\n");
|
||||
}
|
BIN
tests/work1
BIN
tests/work1
Binary file not shown.
@ -1,7 +1,6 @@
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "util.c"
|
||||
|
||||
struct person_tag
|
||||
{
|
||||
@ -61,12 +60,9 @@ int main()
|
||||
|
||||
display_menu();
|
||||
|
||||
scanf("\nenter the option: ", selected);
|
||||
|
||||
newline();
|
||||
|
||||
// scanf("\nenter the option: ", selected);
|
||||
|
||||
// menu(selected);
|
||||
menu(selected);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -109,27 +105,3 @@ void display_menu() {
|
||||
printf("\n");
|
||||
read_file("./../note/section1.txt");
|
||||
}
|
||||
|
||||
void display_students() {
|
||||
|
||||
}
|
||||
|
||||
void search_student() {
|
||||
|
||||
}
|
||||
|
||||
void find_maximum() {
|
||||
|
||||
}
|
||||
|
||||
void find_failed() {
|
||||
|
||||
}
|
||||
|
||||
void update_file() {
|
||||
|
||||
}
|
||||
|
||||
void exit_program() {
|
||||
println("Goodbye...");
|
||||
}
|
Loading…
Reference in New Issue
Block a user