Beruflich Dokumente
Kultur Dokumente
For a singly linked list, write C code to define the data structure and implement three functions 1) insertAtEnd,
2) deleteAtStart and 3) deleteAtEnd. [5 +5+5+5 = 20M]
Assumption data is of type int; other answers are also acceptable. Skipping of typedef is fine for this question. But
then “struct node” or similar should be used instead of Node.
Q2
A. pBus->seats[i] = onWindow; 2M
B. pBus->seats[i] = onAisle; 2M
C. i++ 1M
D. empty 1M
E. pBus->seats[other].status == female && isMale 2M can be swapped with next or differ a bit
F. pBus->seats[other].status == male && !isMale 2M can be swapped with F or differ a bit
G. command[i] == 'M'? 2M
H. sP, pBus, isMale 2M
I. freeBlockedSeats(pBus); 2M
J. false; 1M
K. *refPtr 1M
L. 400: 350; 1M
M. (*refPtr)++ 1M
N. & bus 1M
O. &bus, str, & bookingRefCount 2M
P. &bus 1M
int sID
string
Node *
will use the data type in following manner: float
float
total
group
grade
char
name
char
next
Node * nPtr = malloc(sizeof (Node)); nPtr->name=malloc(64); marks in
5 subjects
nPtr->marks[4]=66.5; [6M]
Q4 A. Write C code for a structure that stores student-ID (max. of 15 characters) and marks in four subjects.
B. Write a function that takes an array of 20 such records and prints the ID and marks of students such that each
line contains details of a single student with ID padded to 16 characters and space separated marks with one digit
after decimal (except if marks are 100). Couple of examples below
2 0 1 7 A 6 P S 1 9 9 9 P 1 0 0 9 9 . 9 4 4 . 5 9 8 . 0 \n
2 0 1 8 B 5 A 6 T S 2 2 2 2 H 8 0 . 5 7 2 . 3 6 9 . 7 5 7 . 7 \n
C. Write a function that sorts the array of 20 such records in ascending order of student ID. [4 + 8 + 8=20M]
A C
typedef struct _studentRec { // typedef optional // can pass address of array as StudentRecord *
char sID[16]; // passing of length as 20 as second arg – optional
float marks[4]; // other sort approaches are also fine
} StudentRecord; // swap function can be defined
void sortRecords(StudentRecord recArray[20]) {
B for(int i=0; i < 20; i++) {
// can pass address of array as StudentRecord * for(int j =i+1; j < 20; j++) {
// optional length (20) as second argument if(strcmp(recArray[i].sID, recArray[j].sID) >0) {
void printRecords(StudentRecord recArray[20]) { StudentRecord temp = recArray[i];
for(int i=0; i < 20; i++) { recArray[i] = recArray[j];
printf("%-16s", recArray[i].sID); recArray[j] = temp;
for(int j =0; j < 4; j++) { }
if(recArray[i].marks[j] >99.999 && }
recArray[i].marks[j] <100.001) }
printf("100"); }
else
printf("%2.1f", recArray[i].marks[j]);
if(j<3) printf(" ");
}
printf("\n");
}
}