Insert a Node at the Tail of a Linked List - data-structures

Node* Insert(Node *head,int data)
{
Node *current=head;
Node *new=(Node *)malloc(size0f(Node));
new->data=data;
while(current->next!=NULL)
{
current=current->next;
}
current->next=new;
new->next=NULL;
return head;
}
Error:
solution.cc: In function 'Node* Insert(Node*, int)':
solution.cc:23:10: error: expected unqualified-id before 'new' Node *new=(Node *)malloc(size0f(Node)); ^
solution.cc:23:10: error: expected initializer before 'new'
solution.cc:24:7: error: expected type-specifier before '->' token new->data=data; ^
solution.cc:29:22: error: expected type-specifier before ';' token current->next=new; ^
solution.cc:30:8: error: expected type-specifier before '->' token new->next=NULL;

I think new is a keyword and you are trying to use that as a variable name in
`Node *new=(Node *)malloc(size0f(Node));`
and subsequent code.
Try replacing it with something like newNode, like below
`Node *newNode=(Node *)malloc(size0f(Node));`
And then use newNode in subsequent code instead of new

I guess #vmachan is right, you shouldn't use new as a variable name.
Besides, I think you were looking for sizeof instead of size0f?

Related

'RedisCluster' has no member named 'get_shards_pool'

I am trying to build DeathStarBench (https://github.com/delimitrou/DeathStarBench), however, I am getting the following error:
In file included from /social-network-microservices/src/HomeTimelineService/HomeTimelineService.cpp:15:0:
/social-network-microservices/src/HomeTimelineService/HomeTimelineHandler.h: In member function 'virtual void social_network::HomeTimelineHandler::WriteHomeTimeline(int64_t, int64_t, int64_t, int64_t, const std::vector&, const std::mapstd::__cxx11::basic_string<char, std::__cxx11::basic_string >&)':
/social-network-microservices/src/HomeTimelineService/HomeTimelineHandler.h:129:55: error: 'class sw::redis::RedisCluster' has no member named 'get_shards_pool'
auto *shards_pool = _redis_cluster_client_pool->get_shards_pool();
I don't know anything about Redis. However, I googled the error message and couldn't find anything related to this. Any suggestions on what might be the problem?

How to get file name that causes GraphQLError: Syntax Error: Unterminated string

In our team we sometimes get an GraphQl syntax error, when modifying our schema.
However, we don't seem to get the name of file causing the issue? The error looks like this:
GraphQLError: Syntax Error: Unterminated string.
at syntaxError (<full-path-to-project>>node_modules/graphql/error/syntaxError.js:15:10)
at readString (<full-path-to-project>>node_modules/graphql/language/lexer.js:513:38)
at readToken (<full-path-to-project>>node_modules/graphql/language/lexer.js:267:14)
at Object.lookahead (<full-path-to-project>>node_modules/graphql/language/lexer.js:54:43)
at Object.advanceLexer [as advance] (<full-path-to-project>>node_modules/graphql/language/lexer.js:44:33)
at Parser.parseStringLiteral (<full-path-to-project>>node_modules/graphql/language/parser.js:519:17)
at Parser.parseDescription (<full-path-to-project>>node_modules/graphql/language/parser.js:728:19)
at Parser.parseFieldDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:856:28)
at Parser.optionalMany (<full-path-to-project>>node_modules/graphql/language/parser.js:1497:28)
at Parser.parseFieldsDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:846:17)
at Parser.parseObjectTypeDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:798:23)
at Parser.parseTypeSystemDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:696:23)
at Parser.parseDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:146:23)
at Parser.many (<full-path-to-project>>node_modules/graphql/language/parser.js:1518:26)
at Parser.parseDocument (<full-path-to-project>>node_modules/graphql/language/parser.js:111:25)
at parse (<full-path-to-project>>node_modules/graphql/language/parser.js:36:17) {
message: 'Syntax Error: Unterminated string.',
locations: [ { line: 27, column: 51 } ]
}
Is this normal - and how do I get the file causing the problem?

Error: invalid argument 0: json: cannot unmarshal hex string of odd length into Go struct field SendTxArgs.data of type hexutil.Bytes

i have a problem that i've been trying to solve for a whole day...
I'm using Vagrant and truffle to migrate a couple of SmartContracts. The problem
occurs right at the migration when i get an error for one of the contracts.
This is the output of the console, any help will be very much appriciated:
Deploying StringUtils...
... 0xfff3df73a1aa886c9006dab692b3dd36fa0f0b4ab1a1f8a933b679c7d17cbadc
StringUtils: 0x9d13c6d3afe1721beef56b55d303b09e021e27ab
Linking StringUtils to Appalto
Deploying Appalto...
... undefined
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: invalid argument 0: json: cannot unmarshal hex string of odd length into Go struct field SendTxArgs.data of type hexutil.Bytes
at Object.InvalidResponse (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\errors.js:38:1)
at C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\requestmanager.js:86:1
at C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:225:1
at C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:64:1)
at XMLHttpRequest._setReadyState (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:509:1)
at IncomingMessage.<anonymous> (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:469:1)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)```

CFE syntax errors

Trying to write a cfengine3 promise that will take an entire directory and move it down one level.
I've used my policy hub to distribute the promise, but I've not yet folded it into my active promise.cf
Here's the promise:
body common control
{
bundlesequence => { dirstructure };
}
#Find out by existance of directories if filesystem is old structure or new
#Set classes for each instance. If old, copy down one level.
#If new file system already, pat yourself on the back
bundle agent dirstructure
{
classes:
"oldFILEstructure"expression => isdir("/old/dir/structure/");
"newFILEstructure" expression => isdir("/new/dir/structure/");
reports:
oldFILEstructure::
"system has old file structure..";
newFILEstructure::
"system has new file structure..";
methods:
oldFILEstructure::
"migratedirectories" usebundle => movedirectories
}
bundle agent movedirectories
{
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
I've used this "isdir" source and this example for local_cp, both from CFE to base the promise on.
When invoked, I get the following error output and I'm trying to figure out why.
:/var/cfengine/inputs/standalone# cf-agent --no-lock --inform --file ./file_structure.cf
./file_structure.cf:41:12: error: syntax error
depth_search => recurse ("inf");
^
./file_structure.cf:41:12: error: Expected promiser string, got 'depth_search'
depth_search => recurse ("inf");
^
./file_structure.cf:41:15: error: Expected ';', got '=>'
depth_search => recurse ("inf");
^
./file_structure.cf:41:23: error: Expected promiser string, got 'recurse'
depth_search => recurse ("inf");
^
./file_structure.cf:41:25: error: Expected ';', got '('
depth_search => recurse ("inf");
^
./file_structure.cf:41:31: error: Expected ';', got ')'
depth_search => recurse ("inf");
^
./file_structure.cf:41:32: error: Expected promiser string, got ';'
depth_search => recurse ("inf");
^
./file_structure.cf:42:1: error: Expected ';', got '}'
}
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
You have an extra semicolon at the end of the copy_from line.
A semicolon ; identifies the end of a promise. Try switching the semicolon at the end of the copy_from line to a comma ,.
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/."),
depth_search => recurse ("inf");
}
Additionally you may want to check out the transformer attribute.
It may or may not be a good use for your case.\
bundle agent example
{
files:
"/old/dir/structure" -> { "jira:EXAMPLE-1234" }
transformer => "/bin/mv /old/dir/structure /new/dir/structure",
comment => "The standard is to use the new location because x, y, z. Bad thing Q or U might happen if this is not managed properly.";
}

Compiling OpenMCU in Linux (Fedora12)

I am tring to compile OpenMCU in fedora 12. Since the orignal project was compiled in VC++, it has some compatiility issues with gcc.
I am using gcc 4.4.4 and febora 12.
The error shows somehting like this.
In file included from mcu.h:84,
from main.cxx:56:
filemembers.h:123: error: ISO C++ forbids declaration of ‘deque’ with no type
filemembers.h:123: error: typedef name may not be a nested-name-specifier
filemembers.h:123: error: expected ‘;’ before ‘<’ token
filemembers.h:124: error: ISO C++ forbids declaration of ‘FilenameList’ with no type
filemembers.h:124: error: expected ‘,’ or ‘...’ before ‘&’ token
In file included from mcu.h:84,
from main.cxx:56:
filemembers.h:149: error: ‘FilenameList’ does not name a type
make: *** [obj_linux_x86_r/main.o] Error 1
when checked in the source code of that perticular file it was something like this...
class ConferenceFileMember : public ConferenceMember
{
PCLASSINFO(ConferenceFileMember, ConferenceMember);
public:
ConferenceFileMember(Conference * conference, const PFilePath & _fn, PFile::OpenMode mode);
*typedef std::deque<PFilePath> FilenameList; //Line 123..*
ConferenceFileMember(Conference * conference, const FilenameList & _fns, PFile::OpenMode mode);
~ConferenceFileMember();
void Unlisten();
Seems to be a simple syntax issue. Can someone help me in this regards?
Thanx in advance..
Looks like std::deque is not defined. Did you #include <deque>?

Resources