Skip to content
Snippets Groups Projects
Commit e938e6ed authored by mathias.catala's avatar mathias.catala
Browse files

update

parent ed25b40b
No related branches found
No related tags found
No related merge requests found
Showing
with 261 additions and 14 deletions
.DS_Store 0 → 100644
File added
No preview for this file type
File added
#include <stdio.h>
#define MAX_SIZE 10cx fdk
struct Stack {
int arr[MAX_SIZE];
int top;
};
// Function to display the current state of the stack
void display(struct Stack *stack) {
printf("Stack:\n");
for (int i = MAX_SIZE - 1; i >= 0; i--) {
if (i <= stack->top) {
printf("| %3d |\n", stack->arr[i]);
} else {
printf("| |\n");
}
printf("-------\n");
}
printf("\n");
}
// Function to initialize the stack
void initialize(struct Stack *stack) {
stack->top = -1;
}
// Function to check if the stack is empty
int isEmpty(struct Stack *stack) {
return stack->top == -1;
}
// Function to check if the stack is full
int isFull(struct Stack *stack) {
return stack->top == MAX_SIZE - 1;
}
// Function to push an element onto the stack
void push(struct Stack *stack, int value) {
if (isFull(stack)) {
printf("Stack overflow\n");
} else {
stack->arr[++stack->top] = value;
printf("%d pushed to stack\n", value);
// Display the current state of the stack
display(stack);
}
}
// Function to pop an element from the stack
int pop(struct Stack *stack) {
if (isEmpty(stack)) {
printf("Stack underflow\n");
return -1; // Assuming -1 represents an error or an invalid value
} else {
// Display the element being popped
printf("%d popped from stack\n", stack->arr[stack->top]);
return stack->arr[stack->top--];
}
}
int main() {
struct Stack myStack;
initialize(&myStack);
push(&myStack, 10);
push(&myStack, 20);
push(&myStack, 30);
printf("Top element is %d\n", myStack.arr[myStack.top]);
pop(&myStack);
pop(&myStack);
printf("Is the stack empty? %s\n", isEmpty(&myStack) ? "Yes" : "No");
return 0;
}
File added
#include <stdio.h>
#include <stdlib.h>
// Define a structure for stack nodes
struct Node {
int data;
struct Node* next;
};
// Define a structure for the stack
struct Stack {
struct Node* top;
};
// Function to initialize an empty stack
void initializeStack(struct Stack* stack) {
stack->top = NULL;
}
// Function to check if the stack is empty
int isEmpty(struct Stack* stack) {
return stack->top == NULL;
}
// Function to push a new element onto the stack
void push(struct Stack* stack, int data) {
// Create a new node
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
if (newNode == NULL) {
fprintf(stderr, "Memory allocation error\n");
exit(EXIT_FAILURE);
}
// Set the data and link to the current top
newNode->data = data;
newNode->next = stack->top;
// Update the top to the new node
stack->top = newNode;
}
// Function to pop an element from the stack
int pop(struct Stack* stack) {
if (isEmpty(stack)) {
fprintf(stderr, "Stack underflow\n");
exit(EXIT_FAILURE);
}
// Pop the top element and update the top
struct Node* temp = stack->top;
int data = temp->data;
stack->top = temp->next;
// Free the memory of the popped node
free(temp);
return data;
}
// Function to get the top element of the stack without popping
int peek(struct Stack* stack) {
if (isEmpty(stack)) {
fprintf(stderr, "Stack is empty\n");
exit(EXIT_FAILURE);
}
return stack->top->data;
}
// Function to display the elements of the stack
void display(struct Stack* stack) {
if (isEmpty(stack)) {
printf("Stack is empty\n");
return;
}
printf("Stack: ");
struct Node* current = stack->top;
while (current != NULL) {
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}
// Function to free the memory used by the stack
void destroyStack(struct Stack* stack) {
while (!isEmpty(stack)) {
pop(stack);
}
}
int main() {
struct Stack myStack;
initializeStack(&myStack);
push(&myStack, 1);
push(&myStack, 2);
push(&myStack, 3);
display(&myStack);
printf("Top element: %d\n", peek(&myStack));
printf("Popped element: %d\n", pop(&myStack));
display(&myStack);
destroyStack(&myStack);
return 0;
}
File added
myTP/TP11/exo1 100644 → 100755
No preview for this file type
No preview for this file type
File added
File added
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.a.out</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
File added
myTP/TP12/exo1 100644 → 100755
No preview for this file type
...@@ -134,7 +134,8 @@ if(dir_add_entry(dir, (person_t){"Christophe", "Charpilloz", (date_t){11, 4, 200 ...@@ -134,7 +134,8 @@ if(dir_add_entry(dir, (person_t){"Christophe", "Charpilloz", (date_t){11, 4, 200
if(dir_add_entry(dir, (person_t){"Emily", "Dickinson", (date_t){19, 8, 1950}, 636363})) return 1; if(dir_add_entry(dir, (person_t){"Emily", "Dickinson", (date_t){19, 8, 1950}, 636363})) return 1;
if(dir_add_entry(dir, (person_t){"Ada", "Lovelace", (date_t){12, 12, 2022}, 12345})) return 1; if(dir_add_entry(dir, (person_t){"Ada", "Lovelace", (date_t){12, 12, 2022}, 12345})) return 1;
if(dir_add_entry(dir, (person_t){"Qwertz", "Uiop", (date_t){1, 1, 562}, 67879})) return 1; if(dir_add_entry(dir, (person_t){"Qwertz", "Uiop", (date_t){1, 1, 562}, 67879})) return 1;
printf("current dir size : %lu \n", dir->size); //printf("current dir size : %d \n", dir->size);
return 0;
} }
...@@ -185,26 +186,24 @@ int main(){ ...@@ -185,26 +186,24 @@ int main(){
char command[255]=" "; char command[255]=" ";
while(strcmp(command,"quit")!=0){ while(strcmp(command,"quit")!=0){
printf("> "); printf("> ");
scanf("%s", &command); scanf("%s", command);
if(strcmp(command,"add")==0){ if(strcmp(command,"add")==0){
person_t new_p; person_t new_p;
printf("Enter the name: "); printf("Enter the name: ");
scanf("%s",&new_p.name); scanf("%s",new_p.name);
printf("Enter the surname: "); printf("Enter the surname: ");
scanf("%s",&new_p.surname); scanf("%s",new_p.surname);
printf("Enter the day of birth: ");
scanf("%s",&new_p.birthday.day);
printf("Enter the day of birth: "); printf("Enter the day of birth: ");
scanf("%s",&new_p.birthday.day); scanf("%i",&new_p.birthday.day);
printf("Enter the month of birth: "); printf("Enter the month of birth: ");
scanf("%s",&new_p.birthday.month); scanf("%d",&new_p.birthday.month);
printf("Enter the year of birth: "); printf("Enter the year of birth: ");
scanf("%s",&new_p.birthday.year); scanf("%d",&new_p.birthday.year);
printf("Enter the phone number: "); printf("Enter the phone number: ");
scanf("%s",&new_p.phone_number); scanf("%d",&new_p.phone_number);
dir_add_entry(&directory,new_p); dir_add_entry(&directory,new_p);
...@@ -213,7 +212,7 @@ int main(){ ...@@ -213,7 +212,7 @@ int main(){
int index; int index;
printf("Enter index to remove: "); printf("Enter index to remove: ");
scanf("%s",&index); scanf("%d",&index);
dir_delete_entry(&directory,index); dir_delete_entry(&directory,index);
printf("Contact removed from Annuary.\n"); printf("Contact removed from Annuary.\n");
...@@ -240,7 +239,7 @@ int main(){ ...@@ -240,7 +239,7 @@ int main(){
int index=-1; int index=-1;
char Surname[255]; char Surname[255];
printf(" Enter Surname: "); printf(" Enter Surname: ");
scanf("%s",&Surname); scanf("%s",Surname);
dir_search_surname(&directory,Surname); dir_search_surname(&directory,Surname);
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.exo1</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
File added
---
triple: 'arm64-apple-darwin'
binary-path: exo1
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _person_print, symObjAddr: 0x0, symBinAddr: 0x100002C9C, symSize: 0x6C }
- { offsetInCU: 0x4D, offset: 0x4D, size: 0x8, addend: 0x0, symName: _person_print, symObjAddr: 0x0, symBinAddr: 0x100002C9C, symSize: 0x6C }
- { offsetInCU: 0x72, offset: 0x72, size: 0x8, addend: 0x0, symName: _dir_init, symObjAddr: 0x6C, symBinAddr: 0x100002D08, symSize: 0x90 }
- { offsetInCU: 0x96, offset: 0x96, size: 0x8, addend: 0x0, symName: _dir_create, symObjAddr: 0xFC, symBinAddr: 0x100002D98, symSize: 0x2C }
- { offsetInCU: 0xBE, offset: 0xBE, size: 0x8, addend: 0x0, symName: _dir_free, symObjAddr: 0x128, symBinAddr: 0x100002DC4, symSize: 0x38 }
- { offsetInCU: 0xE2, offset: 0xE2, size: 0x8, addend: 0x0, symName: _dir_print, symObjAddr: 0x160, symBinAddr: 0x100002DFC, symSize: 0x178 }
- { offsetInCU: 0x16B, offset: 0x16B, size: 0x8, addend: 0x0, symName: _dir_erase, symObjAddr: 0x2D8, symBinAddr: 0x100002F74, symSize: 0x18 }
- { offsetInCU: 0x18F, offset: 0x18F, size: 0x8, addend: 0x0, symName: _dir_add_entry, symObjAddr: 0x2F0, symBinAddr: 0x100002F8C, symSize: 0xEC }
- { offsetInCU: 0x1E2, offset: 0x1E2, size: 0x8, addend: 0x0, symName: _dir_fill, symObjAddr: 0x3DC, symBinAddr: 0x100003078, symSize: 0x4A8 }
- { offsetInCU: 0x20B, offset: 0x20B, size: 0x8, addend: 0x0, symName: _dir_delete_entry, symObjAddr: 0x884, symBinAddr: 0x100003520, symSize: 0xD0 }
- { offsetInCU: 0x259, offset: 0x259, size: 0x8, addend: 0x0, symName: _dir_search_surname, symObjAddr: 0x954, symBinAddr: 0x1000035F0, symSize: 0x10C }
- { offsetInCU: 0x2C7, offset: 0x2C7, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0xA60, symBinAddr: 0x1000036FC, symSize: 0x438 }
...
...@@ -23,8 +23,6 @@ int main() ...@@ -23,8 +23,6 @@ int main()
} }
void reverse_print(char* str){ void reverse_print(char* str){
if(*str){ if(*str){
reverse_print(str+1); reverse_print(str+1);
......
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment