Posts

Showing posts with the label Assignment 8

Assignment 8 Question 1

#include <stdio.h> #include <stdlib.h> struct DoublyLinkedList{ int data; struct DoublyLinkedList *prev; struct DoublyLinkedList *next; }; void removeNode ( struct DoublyLinkedList **headptr, struct DoublyLinkedList **tailptr, struct DoublyLinkedList *ptr) { if ( ptr == *headptr ){ *headptr = ptr->next; (*headptr)->prev = NULL; }else{ if ( ptr == *tailptr ) { *tailptr = ptr->prev; (*tailptr)->next=NULL; }else{ ptr->prev->next = ptr->next; ptr->next->prev = ptr->prev; } } free ( ptr ); ptr = NULL; return; } void removeData ( struct DoublyLinkedList **headptr, struct DoublyLinkedList **tailptr, int n) { struct DoublyLinkedList *curr; curr = *headptr; while ( curr != NULL && curr->data != n ){ curr = curr->next; } if ( curr != NULL ){ removeNode(headptr, tailptr, curr); } return; } struct DoublyLinkedList *createNode(int n) {...

Assignment 8 Question 2

#include <stdio.h> int main() { int n; scanf("%d", &n); int a[4]; int count =0; a[0]=n%1000; n=n/1000; if(a[0]){ count=1; } a[1]=n%100; n=n/100; if(a[1]){ count=2; } a[2]=n%100; n=n/100; if(a[2]){ count=3; } a[3]=n%100; n=n/100; if(a[3]){ count=4; } int i; for(i=0;i<count;i++) { printf("%d\n", a[i]); } return 0; }