Posts

Showing posts from October, 2024

SYBSc (CS) Sem III : Data Structure Slip 20 Que - 2

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q2. There are lists where new elements are always appended at the end of the  list. The list can be implemented as a circular list with the external pointer  pointing to the last element of the list. Implement singly linked circular list  of integers with append and display operations. The operation append(L, n), appends  to the end of the list, n integers either accepted from user or randomly generated. */ #include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; struct node * create(struct node *head) { struct node *newnode = NULL, *temp = NULL; newnode = (struct node*) malloc(sizeof(struct node)); if(newnode!=NULL) {     printf("Enter node data");     scanf("%d",&(newnode->data));   ...

SYBSc (CS) Sem III : Data Structure Slip 14 Que - 2

  SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2 A doubly ended queue allows additions and deletions from both the ends that  is front and rear. Initially additions from the front will not be possible. To avoid this situation, the array can be treated as if it were circular. Implement a  queue library (dstqueue.h) of integers using a static implementation of the  circular queue and implementing the following operations.  a. isFull(Q) b. addFront(Q) c. getRear(Q) d. deleteRear(Q) */ // File name : "dstqueue.c" #include"dstqueue.h" int init(struct Queue *q) {     q->front = q->rear = -1; } int isEmpty(struct Queue *q) {     if(q->front == q->rear)     {        return 1;     }     else{        return 0;     } } int isFul...

SYBSc (CS) Sem III : Data Structure Slip 11 Que - 2

      SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2 Implement a priority queue library (Priority.h) of integers using a  static implementation of the queue and implementing the below two operations.  Write a driver program that includes queue library and calls different queue  operations. 1) Add an element with its priority into the queue. 2) Delete an element from queue according to its priority.  */ // File name : "PriorityQ.c" #include"PriorityQ.h" int initPQ(struct PriorityQueue *pq) {     pq->front = pq->rear = -1;     return 0; } int isFullPQ(struct PriorityQueue *pq) {     if(pq->rear == MAX-1)         return 1;     else         return 0; } int isEmptyPQ(struct PriorityQueue *pq) {     if(pq->front == -1) ...

SYBSc (CS) Sem III : Data Structure Slip 21 Que - 2

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2. Read the data from the file "employee.txt" and sort on names in  alphabetical order (use strcmp) using insertion sort and selection sort */ // File Name: "employee.txt" (This file create separate with txt extension and save in current folder.) John Aniket Julie Dolly Rosemary // File Name: "Slip21_2.c" #include<stdio.h> #include<stdlib.h> #define MAX 20 typedef struct employee{         char name[MAX]; }record; record emp[MAX]; int read_file(record *a){     int i = 0;     FILE *fp;        if ((fp = fopen("employee.txt", "r")) != NULL)     {             while (!feof(fp)){                   fscanf(fp, "%s", a[i].name);     ...

SYBSc (CS) Sem III : Data Structure Slip 21 Que - 1

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 1. Write a program that reverses a string of characters. The function should  use a stack library (cststack.h). Use a static implementation of the stack. */ /// File name : "cststack.h" #include"cststack.h" int init(struct Stack *s) {     s->top = -1; } int isEmpty(struct Stack *s) {     if(s->top == -1)     {        return 1;     }     else{        return 0;     } } int isFull(struct Stack *s) {     if(s->top == MAX-1)     {        return 1;     }     else{        return 0;     } } int Push(struct Stack *s, char x) {     if(isFull(s) == 1)     {        p...

SYBSc (CS) Sem III : Data Structure Slip 17 Que - 2

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2. Write a program that copies the contents of one stack into another. Use  stack library to perform basic stack operations. The order of two stacks must be  identical. (Hint: Use a temporary stack to preserve the order). */ /// File name : "stack.c" #include"stack.h" int init(struct Stack *s) {     s->top = -1; } int isEmpty(struct Stack *s) {     if(s->top == -1)     {        return 1;     }     else{        return 0;     } } int isFull(struct Stack *s) {     if(s->top == MAX-1)     {        return 1;     }     else{        return 0;     } } int Push(struct Stack *s, int n) {   ...

SYBSc (CS) Sem III : Data Structure Slip 17 Que - 1

          SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Implement a list library (singlylist.h) for a singly linked list. Create a  linked list, reverse it and display reversed linked list.*/ /// File name : "singlylist.c" #include"singlylist.h" void CreateList() {      struct node *NewNode = NULL;           NewNode = (struct node *) malloc(sizeof(struct node));           if (NewNode != NULL)      {         NewNode->Next = NULL;                  printf("Enter the data value: ");         scanf("%d", &(NewNode->data));                   if (Head == NULL)         {     ...

SYBSc (CS) Sem III : Data Structure Slip 13 Que - 1

        SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 1. Implement a stack library (ststack.h) of integers using a static  implementation of the stack and implementing the operations like init(S),  S = push(S) and S = pop(S). Write a driver program that includes stack library  and calls different stack operations. */ /// File name : "ststack.c" #include"ststack.h" int init(struct Stack *s) {     s->top = -1; } int isEmpty(struct Stack *s) {     if(s->top == -1)     {        return 1;     }     else{        return 0;     } } int isFull(struct Stack *s) {     if(s->top == MAX-1)     {        return 1;     }     else{        return 0; ...

SYBSc (CS) Sem III : Data Structure Slip 13 Que - 2

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q2 Write a program that sorts the elements of linked list using bubble sort technique */ #include<stdio.h> #include<stdlib.h> struct Node {         int data;         struct Node *Next; }*Head, *Last; void CreateList() {     struct Node *NewNode = (struct Node*) malloc(sizeof(struct Node));          if (NewNode != NULL)     {              printf("Enter the data value: ");              scanf("%d", &(NewNode->data));              NewNode->Next = NULL;                                       if (H...

SYBSc (CS) Sem III : Data Structure Slip 10 Que - 1

      SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 1. Implement a linear queue library (st_queue.h) of integers using a static  implementation of the queue and implementing the init(Q), add(Q) and peek(Q) operations.  Write a program that includes queue library and calls different queue operations.*/ /// File name : "st_queue.c" #include"st_queue.h" int init(struct Queue *q) {     q->front = q->rear = -1; } int isEmpty(struct Queue *q) {     if(q->front == q->rear)     {        return 1;     }     else{        return 0;     } } int isFull(struct Queue *q) {     if(q->rear == MAX-1)     {        return 1;     }     else{        return 0;...

SYBSc (CS) Sem III : Data Structure Slip 8 Que - 2

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2. Write a C program to check whether the contents of two stacks are identical.  Use stack library to perform basic stack operations. Neither stack should be changed.*/ /// File name : "stack.c" #include"stack.h" int init(struct Stack *s) {     s->top = -1; } int isEmpty(struct Stack *s) {     if(s->top == -1)     {        return 1;     }     else{        return 0;     } } int isFull(struct Stack *s) {     if(s->top == MAX-1)     {        return 1;     }     else{        return 0;     } } int Push(struct Stack *s, int n) {     if(isFull(s) == 1)     {       ...

SYBSc (CS) Sem III : Data Structure Slip 8 Que - 1

          SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 1. Implement a list library (singlylist.h) for a singly linked list of integer  with the operations create, delete specific element and display. Write a menu driven  program to call these operations.*/ /// File name : "singlylist.h" #include"singlylist.h" void CreateList() {      struct node *NewNode = NULL;           NewNode = (struct node *) malloc(sizeof(struct node));           if (NewNode != NULL)      {         NewNode->Next = NULL;                  printf("Enter the data value: ");         scanf("%d", &(NewNode->data));                ...

SYBSc (CS) Sem III : Data Structure Slip 7 Que - 1

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q.1 Sort a random array of n integers (accept the value of n from user)  in ascending order by using quick sort algorithm  */ #include<stdio.h> #include<stdlib.h> #define MAX 100 void CreateArray(int A[], int n) {           int i = 0;               for ( i = 0; i < n; i++)           A[i] = rand();  } void DisplayArray(int A[], int n) {      int i = 0;            for ( i = 0; i < n; i++)           printf("%d \t", A[i]);  } void QuickSort(int A[], int low, int high) {           int pivot, t, i, j;            if ( low <= high)   ...

SYBSc (CS) Sem III : Data Structure Slip 7 Que - 2

        SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2 Write a program that checks whether a string of characters is palindrome  or not. The function should use a stack library (cststack.h) of stack of characters  using a static implementation of the stack.  */ /// File name : "cststack.c" #include"cststack.h" int init(struct Stack *s) {     s->top = -1; } int isEmpty(struct Stack *s) {     if(s->top == -1)     {        return 1;     }     else{        return 0;     } } int isFull(struct Stack *s) {     if(s->top == MAX-1)     {        return 1;     }     else{        return 0;     } } int Push(struct Stack *s, char x) { ...

SYBSc (CS) Sem III : Data Structure Slip 6 Que - 2

      SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2 Implement a queue library (dyqueue.h) of integers using a dynamic (linked list)  implementation of the queue and implement init, enqueue, dequeue, isempty, peek operations. */ /// File name : "dyqueue.c" #include"dyqueue.h" int init() {     front = rear = NULL;     return 0; } int isEmpty() {     if((front == NULL && rear == NULL) || front == rear)         return 1;     else         return 0; } void enqueue(int x) {     struct Queue *NewNode = NULL;         NewNode = (struct Queue*) malloc(sizeof(struct Queue));     if (NewNode != NULL)     {        NewNode->data = x;        NewNode->Next = NULL...

SYBSc (CS) Sem III : Data Structure Slip 5 Que - 2

    SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical course based on CS231  /* Q. 2 Implement a priority queue library (Priority.h) of integers using a  static implementation of the queue and implement the below two operations.      1) Add an element with its priority into the queue.      2) Delete an element from queue according to its priority. */ // File name : "PriorityQ.c" #include"PriorityQ.h" int initPQ(struct PriorityQueue *pq) {     pq->front = pq->rear = -1;     return 0; } int isFullPQ(struct PriorityQueue *pq) {     if(pq->rear == MAX-1)         return 1;     else         return 0; } int isEmptyPQ(struct PriorityQueue *pq) {     if(pq->front == -1)         return 1;     else       ...