0% found this document useful (0 votes)
3 views5 pages

New Microsoft Word Document (1)

The document contains C code implementations for a binary tree and a circular queue. The binary tree implementation includes functions for preorder, inorder, and postorder traversals, while the circular queue implementation includes functions for insertion, deletion, and display. Both implementations demonstrate basic data structure operations and memory management in C.

Uploaded by

Ñákúl Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

New Microsoft Word Document (1)

The document contains C code implementations for a binary tree and a circular queue. The binary tree implementation includes functions for preorder, inorder, and postorder traversals, while the circular queue implementation includes functions for insertion, deletion, and display. Both implementations demonstrate basic data structure operations and memory management in C.

Uploaded by

Ñákúl Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1. Show preorder, inorder, postorder representation of Binary Tree.

#include <stdio.h>

#include <stdlib.h>

typedef struct node {

int data;

struct node* left;

struct node* right;

}Node;

Node* createNode(int data) {

Node* q;

q = (Node*)malloc(sizeof(Node));

q->data = data;

q->left = NULL;

q->right = NULL;

return q;

void preOrder(Node *root) {

if (root != NULL){

printf("%d ",root->data);

preOrder(root -> left);

preOrder(root ->right);

void postOrder(Node *root) {

if (root != NULL){

postOrder(root -> left);

postOrder(root ->right);

printf("%d ",root->data);

void InOrder(Node *root) {


if (root != NULL){

InOrder(root -> left);

printf("%d ",root->data);

InOrder(root ->right);

int main() {

Node *p = createNode(4);

Node *p1 = createNode(1);

Node *p2 = createNode(6);

Node *p3 = createNode(5);

Node *p4 = createNode(2);

p -> left = p1;

p -> right = p2;

p1 -> left = p3;

p1 -> right = p4;

preOrder(p);

printf("\n");

postOrder(p);

printf("\n");

InOrder(p);

OUTPUT:
1. Show implementation of circular queue.
#include <stdio.h>

#define N 3

int a[N];

int f=-1,r=-1;

void insert(int x){

if (r==-1&&f==-1)

f=0;

r=0;

a[r]=x;

else if ((r+1)%N==f)

printf("Overflow\n");

else{

r=(r+1)%N;

a[r]=x;

void delete(){

if (f==-1)

printf("Underflow\n");

else if (f==r)

int item=a[f];

printf("deleted item %d ",item);

printf("\n");

f=-1;

r=-1;

}
else

int item;

item=a[f];

printf("deleted item from the beg: %d ",item);

printf("\n");

f=(f+1)%N;

void display(){

int i=f;

if (f==-1&&r==-1)

printf("Queue is empty\n");

else

while (i!=r)

printf("%d ",a[i]);

i=(i+1)%N;

printf("%d",a[r]);

printf("\n");

int main(){

insert(10);

insert(20);

insert(30);

display();

delete();

display();

insert(40);
display();

insert(50);

display();

return 0;

OUTPUT:

You might also like