Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

final Sample. York University EECS 2031

Rating
-
Sold
-
Pages
10
Grade
A+
Uploaded on
18-04-2023
Written in
2022/2023

Consider the following program. #include stdio.h int do_sth (char *s); main(){ char arr [] = "We are the World"; printf ("%dn", do_sth(arr)); } int do_sth(char *s) { char *p = s; while ( *s++ != ‘0’ ) return s - p; } What does function do_sth intend to do? What is the output of the program? In the linked list implementations in labtest 2 and lab, to make the code easier, we declare the head to be a global variable. An alternative way is to declare head as a local variable and pass it as a function parameter. Write a function return_type insertFirst(struct node* head, char d) which inserts in the beginning of the list a new node with data d. You need to define the return type of the function. You also needs to call this function to insert nodes with data ‘A’and ‘E’ into the list. #include stdio.h struct node { char data; struct node *next; }; /************* DO NOT ADD MORE GLOBAL VARIABLES *************/ /*Define your function below:*/ struct node * insertFirst (struct node * list_head, char d){ /***** ADD YOUR CODE HERE *****/ struct node * newP = malloc (sizeof(struct node)); newP - data = d; newP - next = list_head; list_head = newP; return list_h

Show more Read less
Institution
Course

Content preview

Consider the following program.
#include <stdio.h>
int do_sth (char *s);
main(){
char arr [] = "We are the World";
printf ("%d\n", do_sth(arr));
}
int do_sth(char *s)
{
char *p = s;
while ( *s++ != ‘\0’ )
return s - p;
}




What does function do_sth intend to do?



What is the output of the program?

, In the linked list implementations in labtest 2 and lab, to make the code easier, we declare the head to
be a global variable. An alternative way is to declare head as a local variable and pass it as a function
parameter.
Write a function return_type insertFirst(struct node* head, char d) which inserts in
the beginning of the list a new node with data d. You need to define the return type of the function. You
also needs to call this function to insert nodes with data ‘A’and ‘E’ into the list.

#include <stdio.h>

struct node {

char data;
struct node *next;
};

/************* DO NOT ADD MORE GLOBAL VARIABLES *************/

/*Define your function below:*/

struct node * insertFirst (struct node * list_head, char d){

/***** ADD YOUR CODE HERE *****/



struct node * newP = malloc (sizeof(struct node));

newP -> data = d;

newP -> next = list_head;

list_head = newP;



return list_head;

}



main(){

struct node * head;

/* call your function (twice) to insert nodes of data ‘A’‘E’ into list */

head = insertFirst (head, ‘A’);

head = insertFirst (head, ‘E’);

}

Written for

Course

Document information

Uploaded on
April 18, 2023
Number of pages
10
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Themanehoppe American Intercontinental University Online
Follow You need to be logged in order to follow users or courses
Sold
343
Member since
4 year
Number of followers
224
Documents
3784
Last sold
1 day ago

3.5

55 reviews

5
25
4
7
3
7
2
3
1
13

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions