Sitemap
Linking

Linking

Member-only story

C Programming -5

7 min readSep 26, 2024

Yes,

c programming is like starter while learning coding and doing computer science.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h> // For sleep function
#include <arpa/inet.h> // For socket programming

// Example 131: Stack Implementation Using Arrays
#define MAX_STACK 100

struct Stack {
int top;
int items[MAX_STACK];
};

struct Stack* createStack() {
struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack));
stack->top = -1;
return stack;
}

int isFull(struct Stack* stack) {
return stack->top == MAX_STACK - 1;
}

int isEmpty(struct Stack* stack) {
return stack->top == -1;
}

void push(struct Stack* stack, int item) {
if (isFull(stack)) {
printf("Stack overflow\n");
return;
}
stack->items[++stack->top] = item;
}

int pop(struct Stack* stack) {
if (isEmpty(stack)) {
printf("Stack underflow\n");
return -1;
}
return stack->items[stack->top--];
}

// Example 132: Queue Implementation Using Circular Linked List
struct CircularQueueNode {
int data;
struct CircularQueueNode* next;
};

struct CircularQueue {
struct CircularQueueNode* front;
struct CircularQueueNode* rear;
};

// Function to create a new circular queue
struct CircularQueue* createCircularQueue() {
struct CircularQueue* queue = (struct CircularQueue*)malloc(sizeof(struct CircularQueue));
queue->front = queue->rear = NULL;
return queue;
}

// Function to enqueue
void enqueueCircular(struct…

--

--