Commit f7ed68de authored by nathan.smyth's avatar nathan.smyth

Initial commit

parents
,nathan.smyth,cs2-.cs,20.01.2020 11:35,file:///home/nathan.smyth/.config/libreoffice/4;
\ No newline at end of file
File added
section .data
fizz: db 'Fizz', 10
bang: db 'Bang', 10
message: db 'FizzBang Demo', 10
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, message
mov rdx, 14
syscall
;mov rax, 60
;xor rdi, rdi
;syscall
xor rcx, rcx
mov r10, 20
loop1:
mov eax, [rcx]
xor edx, edx
mov ecx, 3
div ecx
cmp edx, 0
je divby3
jmp ex
divby3:
mov ah,09
mov dx,offset fizz
int 21h
ex:
mov eax, [rcx]
xor edx, edx
mov ecx, 5
div ecx
cmp edx, 0
je divby5
jmp ex1
divby5:
mov ah,09
mov dx,offset bang
int 21h
ex1:
inc rcx
cmp rcx,r10
jne loop1
exit:
mov ah,4ch
mov al,00
int 21h
#include <stdio.h>
#include <stdlib.h>
#define SIZE 9
char *strtok(char *str, const char *delim)
typedef int (*comparer)(int, int);
typedef struct node
{
int data;
struct node *left, *right;
} node;
typedef void (*callback)(node*);
int main ()
{
int a[18];
int j =0;
const char s[2] = ",";
char *token;
int bufferlength = 255;
char buffer[bufferlength];
FILE *file = fopen("pg03data", "r");
if(! file)
{
printf("Error, file not found\n");
exit(-1);
}
while(fgets(buffer,bufferlength,file)!=NULL)
{
token = strtok((fgets(buffer,bufferlength)),s);
a[j] = token;
j+=;
}
node* root = NULL;
comparer int_comp = compare;
int i;
for(i=0; i<18; i++)
{
printf("%d ",a[i]);
root = insert(root,int_comp,a[i]);
}
fclose(file);
}
node* createNode(int data)
{
node *new_node = (node*)malloc(sizeof(node));
new_node->data = data;
new_node->left = NULL;
new_node->right = NULL;
return new_node;
}
node* insert(node *root,comparer compare, int data)
{
if(root == NULL)
{
root = createnode(data);
}
else
{
int isLeft = 0;
int r = 0;
node* pointer = root;
node* previous = NULL;
while(pointer != NULL)
{
r = compare(data,pointer->data);
previous = pointer;
if(r < 0)
{
isLeft = 1;
pointer = pointer->left;
}
else if(r >0)
{
isLeft = 0;
pointer = pointer->right;
}
if(isLeft)
previous->left = createNode(data);
else
previous->right = createNode(data);
}
return root;
}
int compare(int left, int right)
{
if(left < right)
return 1;
if(left > right)
return -1;
return 0;
{
void inorder(node *root, callback cb)
{
node *pointer, *pre;
if(root ==NULL)
return;
pointer = root;
while(pointer != NULL)
{
if(pointer->left != NULL)
{
cb(pointer);
pointer = pointer->right;
}
else
{
pre = pointer->left;
while(pre->right != NULL && pre->right != pointer)
pre = pre->right;
if (pre->right != NULL)
{
pre->right = pointer;
pointer = pointer->left;
}
else
{
pre->right = NULL;
cb(pointer);
pointer = pointer->right;
}
}
}
}
File added
#include <stdio.h>
int main(void)
{
int i;
int fizz = 0;
int bang = 0;
printf("FizzBang demo\n");
for(i=1; i<21; i++)
{
if(i %3 == 0)
{
printf("Fizz");
fizz = fizz + 1;
}
if(i % 5 == 0)
{
printf("Bang");
bang = bang +1;
}
else if((i % 3 == 0)&&(i % 5 ==0))
{
printf("FizzBang");
bang = bang +1;
fizz = fizz + 1;
}
if((i%3 !=0)&&(i%5!=0))
{
printf("%d", i);
}
printf("\n");
}
printf("%d\n",fizz);
printf("%d\n",bang);
return 0;
}
2103, Networking, Year 02, Semester 01
3109, Advanced Web Development, Year 03, Semester 02
1101, Programming 01, Year 01, Semester 01
2107, Mobile Programming, Year 02, Semester 02
1103, Computer Fundamentals, Year 01, Semester 01
3101, Major Project, Year 03, Semester 01
1105, Programming 02, Year 01, Semester 02
2108, Professional Project, Year 02, Semester 02
1106, Software Engineering, Year 01, Semester 02
2102, Databases, Year 02, Semester 01
3105, The Internet Of Things, Year 03, Semester 01
3107, Artificial Intelligence, Year 03, Semester 02
3108, Cybercrime Security, Year 03, Semester 02
1102, Mathematics, Year 01, Semester 01
1107, Technology In Context, Year 01, Semester 02
2101, Programmming 03, Year 02, Semester 01
2109, Philosophies of Technology, Year 02, Semester 02
3104, Human Computer Interaction, Year 03, Semester 01
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment