SE250:lab-4:mgha023

From Marks Wiki
Jump to navigation Jump to search

Right.So I'd typed up my lab report and I tried embedding an image and the whole thing got deleted for some reason.So here we go again...

At the start of the lab, I was unsure as to what the symbol '->' did. I guess it was very obvious for everyone else in the lab but I think I'm really weak at 250 and so I didn't really know what I was doing for a long time.I tired looking for explanations in my lecture notes but I could not figure out what it really did. So I took the help of the tutor and I was told that -> is either referring to a head or tail.

For example, in the case of 'list->head', it's referring to the first element in the linked list 'box'. On the other hand, 'list->tail' is referring to the element the tail is pointing to.

I tried uploading my diagram but it failed again. I think I'll try again later.

After understanding what -> did, i tried question one which as quite ok...This was my code:

 int length(Cons* list) {
	int index=0;
	for ( ; list != nil; list = list->tail){
		index++;
	}
	printf("%d\n", list->tail);
	return index;
 }

I tried to Build it but i got an error saying that I had to include a file called "stdafx". So i tried the following:

#include "stdafx.h"

and then when i tried to build it again, it popped up an error that it could not find any such file. I then asked for the tutors help.We realised that I hadn't been logged on onto my home directory and that my program was saved in the C:\ which was not what we wanted. We tried locating my home drive but it wasn't found. So we saved the file on my USB drive and then tried building the code from there. It then worked and popped up errors from the rest of my program. I'm not too good at writing code in C and I tried revising the lecture notes to see where I was going wrong...

Initially I had:

   int element_t first(Cons* list){
   	
  	if (element_t != nil){
 		printf("%d\n", element_t);
 	}
 	else return 0;
   }

which is wrong. I don't think I had understood the question properly. What I needed was to return the first element of the linked list and this was nto doing that. How I refer to the first element should have been by using list->head as the tutor had taught me earlier. I tried modifying the code accordingly and this is what I got:

 int element_t first(Cons* list){
	
	if (list->head != nil){
		printf("%d\n", list->head);
 	}
	else return 0;
}

I'm still not sure if this is completely right, but I guess I understand what I'm trying to do, although I'm not sure how to put it down in code (although that's partly the point!).I also have an error(which is bad) that says: Error 1 error C2061: syntax error : identifier 'first'. Unfortunately I'm quite terrible at code so I'm unsure of what to do.

The next question was to write a function for element_t second(Cons*). I figured that perhaps this time I was to use list->tail. So this is the code I ended up writing:

int element_t second(Cons* list){
	
	if (list->tail != nil){
		printf("%d\n", list->tail);
	}
	else return 0;
}

Again I'm not sure if this is right. I have an error when I build it that says:

Error 1 error C2061: syntax error : identifier 'second'

For the next part,viz.,code to see if they have exactly the smae elements this was my code:

int equal(Cons *list1, Cons *list2){
	true=1;
	false=0;
	if ((length(Cons *list1)) == (length(Cons *list2))){
		return true;
	}
	else return false;
}

Again this is just comparing the lengths and not checking if the elements are the same and in identical order.So, this code is wrong.

I'm really not sure how to put down ideas in code. I get very confused with all the names and symbols that it stops making sense to me. I guess that's because I'm new to the whole programming thing and never done anything like this before.I've seen a pattern in all my labs.For the first 15 mins I don't have any idea of what I'm doing. I try understanding the question and try to avoid asking for help right in the beginning as I want to see if I can understand it myself. I try many different things in vain. Then inevitably, I ask for help. What I need at the start of every lab is to be started off. Call it 'starting trouble', but if someone tells me where I'm going, I get the point after that. But if I don't get that initial push, I'm lost throughout the entire lab. This is exactly what happened today. I thought I'd wait and try to figure it out myself and didn't ask for help initially because I guess we were supposed to know all that was in the lab handout. So since I didn't reach out for that initial push, I had no clue if what I was doing was right or wrong. By the end of the hour, I was still in the second question, and although I needed help, I hesitated because I felt 1 hour was too long a time to spend on a 'simple' question. I perhaps was afraid to ask for help as I was lagging behind.This is where I went wrong. I should have just put up my hand however late it was and admit that I was stuck. I guess I thought that if I asked for help, it would be assumed that I'm not trying hard enough and applying my mind to the problem. But that is not the case. I really try hard to understand and see what the question is asking but somehow, this whole 'data structures' topic hasn't clicked for me. I'm yet to assimilate it all. Yet to absorb it and see where it is heading. This is the reason why I am lost in labs because although I try really hard to come up with something, I have no background knowledge to fall back on to see whether I'm on the right track. In fact, I don't know what the right track is at all. I usually have no strategy.Because I'm not sure what to do. I need that initial hint to get started.Just a push in the right direction. This is my problem and that is why I haven't been very efficient in this lab. I guess this is just me, but I find the lectures a little brief and 'high level' for me to assimilate. There is no time to chew upon things in the lecture as everyhting is being introduced so quickly.I find them a little too fast. I guess this is because of my lack of previous experience in C. The whole thing is just so new and abstract to me that I find it hard to take away everything that is covered in the lectures and put it to practice in the lab.


  • !!! Ask around for Shrek, David or Hannah during the labs. We're cool to help you out. Are you AP or something? Shrek
  • Hey, youre not the only one thats lost, if thats any consolation. :)
  • hey guys, Medha is a AP student, so obviously this stuff is pretty hard for her since she hasn't done 131 like us.
  • Message to medha: We love u :D Dont worry, u'll be fine. if the lecturer/tutor are not much help in the labs, just ask any of us students :) this is Samar and Archana btw hehe :D