Disclosure:

WPrBlogger content is reader-supported. If you click our affiliate links to purchase products or services on the merchant website, we will earn commision, but at no additional cost.

Data Structures Through C In Depth S.k. Srivastava Pdf

For example, here is an original implementation of a stack using a dynamically allocated array (similar to what Srivastava’s book would show):

#include <stdio.h>
#include <stdlib.h>

typedef struct int *arr; int top; int capacity; Stack;

Stack* createStack(int capacity) Stack s = (Stack)malloc(sizeof(Stack)); s->capacity = capacity; s->top = -1; s->arr = (int*)malloc(capacity * sizeof(int)); return s;

void push(Stack *s, int data) if (s->top == s->capacity - 1) printf("Stack overflow\n"); return; s->arr[++s->top] = data; data structures through c in depth s.k. srivastava pdf

int pop(Stack *s) if (s->top == -1) printf("Stack underflow\n"); return -1; return s->arr[s->top--];

int peek(Stack *s) if (s->top == -1) return -1; return s->arr[s->top];

int isEmpty(Stack *s) return s->top == -1; For example, here is an original implementation of

void freeStack(Stack *s) free(s->arr); free(s);

int main() Stack *s = createStack(5); push(s, 10); push(s, 20); printf("Popped: %d\n", pop(s)); freeStack(s); return 0;


The book provides the foundation. Your job is to extend it.

  • Arrays:
  • While S.K. Srivastava’s book is excellent, consider these alternatives for a rounded perspective:

    Scroll to Top