iamlam / c Goto Github PK
View Code? Open in Web Editor NEWSerie de ejercicios de programación en C++ : Estructuras básicas, punteros, pilas,colas,listas enlazadas, arboles
Serie de ejercicios de programación en C++ : Estructuras básicas, punteros, pilas,colas,listas enlazadas, arboles
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 100 // Tamaño máximo para la pila y la cola
// Estructura para los nodos de la pila y la cola
struct Node {
int data;
struct Node* next;
};
// Estructura para la pila
struct Stack {
struct Node* top;
};
// Estructura para la cola simple
struct Queue {
struct Node *front, *rear;
};
// Función para inicializar una pila
struct Stack* createStack() {
struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack));
stack->top = NULL;
return stack;
}
// Función para inicializar una cola simple
struct Queue* createQueue() {
struct Queue* queue = (struct Queue*)malloc(sizeof(struct Queue));
queue->front = queue->rear = NULL;
return queue;
}
// Función para crear un nuevo nodo
struct Node* newNode(int data) {
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->next = NULL;
return node;
}
// Función para empujar un elemento a la pila
void push(struct Stack* stack, int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = stack->top;
stack->top = newNode;
printf("%d pushed to stack\n", data);
}
// Función para sacar un elemento de la pila
int pop(struct Stack* stack) {
if (stack->top == NULL) {
printf("Stack underflow\n");
return -1;
}
struct Node* temp = stack->top;
int popped = temp->data;
stack->top = stack->top->next;
free(temp);
return popped;
}
// Función para mostrar la pila
void showStack(struct Stack* stack) {
struct Node* temp = stack->top;
printf("Stack: ");
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
printf("\n");
}
// Función para insertar un elemento en la cola simple
void enqueue(struct Queue* queue, int data) {
struct Node* newNode = newNode(data);
if (queue->rear == NULL) {
queue->front = queue->rear = newNode;
return;
}
queue->rear->next = newNode;
queue->rear = newNode;
}
// Función para eliminar un elemento de la cola simple
int dequeue(struct Queue* queue) {
if (queue->front == NULL) {
printf("Queue is empty\n");
return -1;
}
struct Node* temp = queue->front;
int item = temp->data;
queue->front = queue->front->next;
if (queue->front == NULL)
queue->rear = NULL;
free(temp);
return item;
}
// Función para mostrar la cola simple
void showQueue(struct Queue* queue) {
struct Node* temp = queue->front;
printf("Queue: ");
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
printf("\n");
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.