Your first program is incomplete, List and sNode aren't defined anywhere, which is why it looks so weird. I can probably assume list and snode are the same, so they look like this:
It is a linked list, where each element holds a reference to the next one, or a NULL reference if the list is ending.
After the first loop it looks like this:
Second loop:
etc.
You can see how they create a new node with "malloc", set it to point to the old node t->next=l; and then make the root point to it l=t;
I cannot grasp that python code at all, so I can't tell how or if it's related to this, though I suspect python doesn't actually have a linked list -- it's a higher level language, operating above the level where you'd know or care how it remembers what elements go where.
Your first program is incomplete, List and sNode aren't defined anywhere, which is why it looks so weird. I can probably assume list and snode are the same, so they look like this:
It is a linked list, where each element holds a reference to the next one, or a NULL reference if the list is ending.
After the first loop it looks like this:
Second loop:
etc.
You can see how they create a new node with "malloc", set it to point to the old node t->next=l; and then make the root point to it l=t;
I cannot grasp that python code at all, so I can't tell how or if it's related to this, though I suspect python doesn't actually have a linked list -- it's a higher level language, operating above the level where you'd know or care how it remembers what elements go where.
Thank you! That helps a lot.
I am a little confused on this one also. What would this display?
This is a simplified representation of how the table array would look:
Thank you ^^ but can you explain how you got that?
Also, I was wondering if it was possible to write a function that takes a key and a reference to an integer and fills in the reference with the appropriate value, while returning true? If possible, how would you write it?
Last edited by totoro125; 10-25-2014 at 11:42 PM..
entry* table[ TABLE_SIZE ] = { NULL }; this statement initializes the "table" array as a TABLE_SIZE (7) element array with NULL pointers. In C arrays are indexed from zero so we end up with:
I use (Undefined) here, as the table array element contains a NULL pointer. In the context of this code (empty) could be a better analogy.
The insert code calculates a hash value of the input string being the length of the string modulo the TABLE_SIZE (7). This is a pretty simple hash which results in strings of various lengths being inserted into the table array as follows:
Looking at this code in the insert function:
we can see that each element of table is a linked list and new values are inserted at the front of the list.
So "Jaga" is inserted into the table[4] list first, then later "Kate" is inserted in front of "Jaga" then "Nash", and so forth.
Here is the update code you requested:
Last edited by Chubler_XL; 10-26-2014 at 05:30 PM..
This User Gave Thanks to Chubler_XL For This Post:
entry* table[ TABLE_SIZE ] = { NULL }; this statement initializes the "table" array as a TABLE_SIZE (7) element array with NULL pointers. In C arrays are indexed from zero so we end up with:
I use (Undefined) here, as the table array element contains a NULL pointer. In the context of this code (empty) could be a better analogy.
The insert code calculates a hash value of the input string being the length of the string modulo the TABLE_SIZE (7). This is a pretty simple hash which results in strings of various lengths being inserted into the table array as follows:
Looking at this code in the insert function:
we can see that each element of table is a linked list and new values are inserted at the front of the list.
So "Jaga" is inserted into the table[4] list first, then later "Kate" is inserted in front of "Jaga" then "Nash", and so forth.
Here is the update code you requested:
Thank you so much! This helps a lot =D
One last thing, would you happen to know how to run the python code? I know it's incomplete but I am not sure what to add so I can make it run and see the output.
Is there a way I can specify the name of a list as an argument to a shell script and then use the values of that list name in the script?
I need to do this WITHOUT using case statements.
Something like this:
check.sh list1
#!/bin/bash
list1="www.amazon.com www.google.com"... (9 Replies)
Hi all,
I have a PLSQL script which has a IN list where it takes some ids as input. For example
SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID IN (comma separated list )
I want to run this quest inside a shell script but I would like to prepare the IN list dynamically where the employee ids... (1 Reply)
Hello everyone - I have the task to create a file list script that will list files in directory based on the parameters passed to the program.
It has to be a C Shell - I mentioned that before but I got closed :) - the company only allows this shell for security purposes I guess.
Anyway, here is... (4 Replies)
EDIT : This is for perl
@data2 = grep(/$data/, @list_now);
This gives me @data2 as
Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared
But I really cant access data2 by its individual elements.
$data2 is the entire list, while $data,2,3...... (1 Reply)
Hi Friend,
I have a small script to list all file FFAAAAABBBBB00001 and FFAAAAABBBBB00001.repaired (when I run another script, the orginal file will output another *.repaired file) in my unix directory, and reaname the output file FFAAAAABBBBB00001.repaired back to FFAAAABBBBB00001. However, it... (2 Replies)
Hi All I have two scripts which i used to try and list all the directories one using 'function', which only lists the first directory and does not show directories within directories.
function ListDir ()
{
for arg in $(ls $HOME)
do
if
then
echo $arg
... (2 Replies)
Hi all,
First of all compliments on the forum here. Looks great and has lots of information, some of which I have been able to use. I am a relativ noob when it comes to Unix but already I have been fooling around with scripts for the company I work for here in switzerland!
Thanks to this... (2 Replies)
hey, im trying to write a script that will list all the .c files, and give me the first 10 lines of code in them. I think ive got that bit working, but i want to make it use friendly so i can select whether i want to modify a .c file or delete it. (7 Replies)
Hello guys it's me again, I need some help. What I'm doing is listing all the file and directories Recusively and using it a a master file. Then I need to do the same the nest day to make sure nothing was deleted or modified. What happen is file in one of out major directories was deleted without... (2 Replies)